2008-10-25 16:42:38 +00:00
|
|
|
require File.expand_path(File.dirname(__FILE__) + '/helper')
|
2008-08-27 00:21:27 +00:00
|
|
|
|
|
|
|
describe Webrat::RailsSession do
|
|
|
|
it "should delegate response_body to the session response body" do
|
|
|
|
response = mock("response", :body => "<html>")
|
|
|
|
integration_session = mock("integration session", :response => response)
|
|
|
|
Webrat::RailsSession.new(integration_session).response_body.should == "<html>"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should delegate response_code to the session response code" do
|
|
|
|
response = mock("response", :code => "42")
|
|
|
|
integration_session = mock("integration session", :response => response)
|
|
|
|
Webrat::RailsSession.new(integration_session).response_code.should == 42
|
|
|
|
end
|
|
|
|
|
2008-11-05 23:15:12 +00:00
|
|
|
it "should delegate get to request_via_redirect on the integration session" do
|
2008-08-27 00:21:27 +00:00
|
|
|
integration_session = mock("integration session")
|
|
|
|
rails_session = Webrat::RailsSession.new(integration_session)
|
2008-11-05 23:15:12 +00:00
|
|
|
integration_session.should_receive(:request_via_redirect).with(:get, "url", "data", "headers")
|
2008-08-27 00:21:27 +00:00
|
|
|
rails_session.get("url", "data", "headers")
|
|
|
|
end
|
|
|
|
|
2008-11-05 23:15:12 +00:00
|
|
|
it "should delegate post to request_via_redirect on the integration session" do
|
2008-08-27 00:21:27 +00:00
|
|
|
integration_session = mock("integration session")
|
|
|
|
rails_session = Webrat::RailsSession.new(integration_session)
|
2008-11-05 23:15:12 +00:00
|
|
|
integration_session.should_receive(:request_via_redirect).with(:post, "url", "data", "headers")
|
2008-08-27 00:21:27 +00:00
|
|
|
rails_session.post("url", "data", "headers")
|
|
|
|
end
|
|
|
|
|
2008-11-05 23:15:12 +00:00
|
|
|
it "should delegate put to request_via_redirect on the integration session" do
|
2008-08-27 00:21:27 +00:00
|
|
|
integration_session = mock("integration session")
|
|
|
|
rails_session = Webrat::RailsSession.new(integration_session)
|
2008-11-05 23:15:12 +00:00
|
|
|
integration_session.should_receive(:request_via_redirect).with(:put, "url", "data", "headers")
|
2008-08-27 00:21:27 +00:00
|
|
|
rails_session.put("url", "data", "headers")
|
|
|
|
end
|
|
|
|
|
2008-11-05 23:15:12 +00:00
|
|
|
it "should delegate delete to request_via_redirect on the integration session" do
|
2008-08-27 00:21:27 +00:00
|
|
|
integration_session = mock("integration session")
|
|
|
|
rails_session = Webrat::RailsSession.new(integration_session)
|
2008-11-05 23:15:12 +00:00
|
|
|
integration_session.should_receive(:request_via_redirect).with(:delete, "url", "data", "headers")
|
2008-08-27 00:21:27 +00:00
|
|
|
rails_session.delete("url", "data", "headers")
|
|
|
|
end
|
|
|
|
|
|
|
|
context "the URL is a full path" do
|
|
|
|
it "should just pass on the path" do
|
|
|
|
integration_session = mock("integration session", :https! => nil)
|
|
|
|
rails_session = Webrat::RailsSession.new(integration_session)
|
2008-11-05 23:15:12 +00:00
|
|
|
integration_session.should_receive(:request_via_redirect).with(:get, "/url", "data", "headers")
|
2008-08-27 00:21:27 +00:00
|
|
|
rails_session.get("http://www.example.com/url", "data", "headers")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "the URL is https://" do
|
2008-10-22 04:55:58 +00:00
|
|
|
it "should call #https! with true before the request and just pass on the path" do
|
2008-11-14 05:04:53 +00:00
|
|
|
integration_session = mock("integration session")
|
2008-08-27 00:21:27 +00:00
|
|
|
rails_session = Webrat::RailsSession.new(integration_session)
|
|
|
|
integration_session.should_receive(:https!).with(true)
|
2008-11-14 05:04:53 +00:00
|
|
|
integration_session.should_receive(:request_via_redirect).with(:get, "/url", "data", "headers")
|
2008-08-27 00:21:27 +00:00
|
|
|
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
|
2008-11-05 23:15:12 +00:00
|
|
|
integration_session = mock("integration session", :request_via_redirect => nil)
|
2008-08-27 00:21:27 +00:00
|
|
|
rails_session = Webrat::RailsSession.new(integration_session)
|
|
|
|
integration_session.should_receive(:https!).with(false)
|
|
|
|
rails_session.get("http://www.example.com/url", "data", "headers")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should provide a saved_page_dir" do
|
|
|
|
Webrat::RailsSession.new(mock("integration session")).should respond_to(:saved_page_dir)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should provide a doc_root" do
|
|
|
|
Webrat::RailsSession.new(mock("integration session")).should respond_to(:doc_root)
|
|
|
|
end
|
|
|
|
end
|