webrat/spec/private/rails/rails_adapter_spec.rb

114 lines
4.3 KiB
Ruby
Raw Normal View History

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2009-08-27 04:56:39 +00:00
require "action_controller"
require "webrat/rails"
2009-08-13 00:52:57 +00:00
describe Webrat::RailsAdapter do
before :each do
Webrat.configuration.mode = :rails
@integration_session = mock("integration_session")
end
it "should delegate response_body to the session response body" do
@integration_session.stub!(:response => mock("response", :body => "<html>"))
2009-08-13 00:52:57 +00:00
Webrat::RailsAdapter.new(@integration_session).response_body.should == "<html>"
end
it "should delegate response_code to the session response code" do
@integration_session.stub!(:response => mock("response", :code => "42"))
2009-08-13 00:52:57 +00:00
Webrat::RailsAdapter.new(@integration_session).response_code.should == 42
end
it "should delegate get to the integration session" do
@integration_session.should_receive(:get).with("url", "data", "headers")
2009-08-13 00:52:57 +00:00
rails_session = Webrat::RailsAdapter.new(@integration_session)
rails_session.get("url", "data", "headers")
end
it "should delegate post to the integration session" do
@integration_session.should_receive(:post).with("url", "data", "headers")
2009-08-13 00:52:57 +00:00
rails_session = Webrat::RailsAdapter.new(@integration_session)
rails_session.post("url", "data", "headers")
end
it "should delegate put to the integration session" do
@integration_session.should_receive(:put).with("url", "data", "headers")
2009-08-13 00:52:57 +00:00
rails_session = Webrat::RailsAdapter.new(@integration_session)
rails_session.put("url", "data", "headers")
end
it "should delegate delete to the integration session" do
@integration_session.should_receive(:delete).with("url", "data", "headers")
2009-08-13 00:52:57 +00:00
rails_session = Webrat::RailsAdapter.new(@integration_session)
rails_session.delete("url", "data", "headers")
end
context "the URL is a full path" do
it "should pass the full url" do
@integration_session.stub!(:https!)
@integration_session.should_receive(:get).with("http://www.example.com/url", "data", "headers")
2009-08-13 00:52:57 +00:00
rails_session = Webrat::RailsAdapter.new(@integration_session)
rails_session.get("http://www.example.com/url", "data", "headers")
end
end
context "the URL is https://" do
it "should call #https! with true before the request before passing along the full url" do
@integration_session.should_receive(:https!).with(true)
@integration_session.should_receive(:get).with("https://www.example.com/url", "data", "headers")
2009-08-13 00:52:57 +00:00
rails_session = Webrat::RailsAdapter.new(@integration_session)
rails_session.get("https://www.example.com/url", "data", "headers")
end
end
context "the URL is http://" do
it "should call #https! with true before the request" do
@integration_session.stub!(:get)
@integration_session.should_receive(:https!).with(false)
2009-08-13 00:52:57 +00:00
rails_session = Webrat::RailsAdapter.new(@integration_session)
rails_session.get("http://www.example.com/url", "data", "headers")
end
end
context "the URL include an anchor" do
it "should strip out the anchor" do
@integration_session.should_receive(:https!).with(false)
@integration_session.should_receive(:get).with("http://www.example.com/url", "data", "headers")
2009-08-13 00:52:57 +00:00
rails_session = Webrat::RailsAdapter.new(@integration_session)
rails_session.get("http://www.example.com/url#foo", "data", "headers")
end
end
it "should provide a saved_page_dir" do
2009-08-13 00:52:57 +00:00
Webrat::RailsAdapter.new(mock("integration session")).should respond_to(:saved_page_dir)
end
it "should provide a doc_root" do
2009-08-13 00:52:57 +00:00
Webrat::RailsAdapter.new(mock("integration session")).should respond_to(:doc_root)
end
2009-04-08 00:30:12 +00:00
it "should accept an ActiveRecord argument to #within and translate to a selector using dom_id" do
pending "Move this to spec/public/within_spec.rb"
body = <<-HTML
<a href="/page1">Edit</a>
<div id="new_object">
<a href="/page2">Edit</a>
</div>
HTML
2009-04-08 00:30:12 +00:00
response = mock("response", :body => body, :headers => {}, :code => 200)
@integration_session.stub!(:response => response)
@integration_session.should_receive(:get).with("/page2", {}, nil)
2009-04-08 00:30:12 +00:00
2009-08-13 00:52:57 +00:00
rails_session = Webrat::RailsAdapter.new(@integration_session)
2009-04-08 00:30:12 +00:00
object = Object.new
object.stub!(:id => nil)
2009-04-08 00:30:12 +00:00
rails_session.within(object) do
rails_session.click_link 'Edit'
end
end
2009-04-08 00:30:12 +00:00
end