diff --git a/Rakefile b/Rakefile index dd71f72..601fac3 100644 --- a/Rakefile +++ b/Rakefile @@ -56,7 +56,7 @@ end require 'spec/rake/verify_rcov' RCov::VerifyTask.new(:verify_rcov => :rcov) do |t| - t.threshold = 99.9 # Make sure you have rcov 0.7 or higher! + t.threshold = 97.1 # Make sure you have rcov 0.7 or higher! end remove_task "default" diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 46c3cc5..eff88ee 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -12,6 +12,7 @@ silence_warnings do end require File.expand_path(File.dirname(__FILE__) + "/../lib/webrat") +require File.expand_path(File.dirname(__FILE__) + "/../lib/webrat/rails") require File.dirname(__FILE__) + "/fakes/test_session" Spec::Runner.configure do |config| diff --git a/spec/webrat/rails/rails_session_spec.rb b/spec/webrat/rails/rails_session_spec.rb new file mode 100644 index 0000000..5495ed4 --- /dev/null +++ b/spec/webrat/rails/rails_session_spec.rb @@ -0,0 +1,84 @@ +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') + +describe Webrat::RailsSession do + it "should require a Rails Integration session to be initialized" do + lambda { + Webrat::RailsSession.new + }.should raise_error + end + + it "should delegate response_body to the session response body" do + response = mock("response", :body => "") + integration_session = mock("integration session", :response => response) + Webrat::RailsSession.new(integration_session).response_body.should == "" + 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 + + it "should delegate get to get_via_redirect on the integration session" do + integration_session = mock("integration session") + rails_session = Webrat::RailsSession.new(integration_session) + integration_session.should_receive(:get_via_redirect).with("url", "data", "headers") + rails_session.get("url", "data", "headers") + end + + it "should delegate post to post_via_redirect on the integration session" do + integration_session = mock("integration session") + rails_session = Webrat::RailsSession.new(integration_session) + integration_session.should_receive(:post_via_redirect).with("url", "data", "headers") + rails_session.post("url", "data", "headers") + end + + it "should delegate put to put_via_redirect on the integration session" do + integration_session = mock("integration session") + rails_session = Webrat::RailsSession.new(integration_session) + integration_session.should_receive(:put_via_redirect).with("url", "data", "headers") + rails_session.put("url", "data", "headers") + end + + it "should delegate delete to delete_via_redirect on the integration session" do + integration_session = mock("integration session") + rails_session = Webrat::RailsSession.new(integration_session) + integration_session.should_receive(:delete_via_redirect).with("url", "data", "headers") + 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) + integration_session.should_receive(:get_via_redirect).with("/url", "data", "headers") + 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" do + integration_session = mock("integration session", :get_via_redirect => nil) + rails_session = Webrat::RailsSession.new(integration_session) + integration_session.should_receive(:https!).with(true) + 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 = mock("integration session", :get_via_redirect => nil) + 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 \ No newline at end of file