diff --git a/lib/webrat/rails.rb b/lib/webrat/rails.rb index 6fd38f9..f3f8379 100644 --- a/lib/webrat/rails.rb +++ b/lib/webrat/rails.rb @@ -1,4 +1,6 @@ require "webrat" + +require "action_controller" require "action_controller/integration" module Webrat diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 640b41d..c33b55d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -7,27 +7,9 @@ begin require "redgreen" unless ENV['TM_CURRENT_LINE']; rescue LoadError; end webrat_path = File.expand_path(File.dirname(__FILE__) + "/../lib/") $LOAD_PATH.unshift(webrat_path) unless $LOAD_PATH.include?(webrat_path) -require "merb-core" -require "webrat/merb" - require "webrat" require File.expand_path(File.dirname(__FILE__) + "/fakes/test_session") -Spec::Runner.configure do |config| - include Webrat::Methods - - def with_html(html) - raise "This doesn't look like HTML. Wrap it in a tag" unless html =~ /^\s*<[^Hh>]*html/i - webrat_session.response_body = html - end - - def with_xml(xml) - raise "This looks like HTML" if xml =~ /^\s*<[^Hh>]*html/i - webrat_session.response_body = xml - end - -end - module Webrat @@previous_config = nil @@ -38,10 +20,30 @@ module Webrat def self.reset_for_test @@configuration = @@previous_config if @@previous_config end +end + +Spec::Runner.configure do |config| + include Webrat::Methods - class Configuration - def mode_for_test= (mode) - @mode = mode - end + def with_html(html) + raise "This doesn't look like HTML. Wrap it in a tag" unless html =~ /^\s*<[^Hh>]*html/i + webrat_session.response_body = html end -end \ No newline at end of file + + def with_xml(xml) + raise "This looks like HTML" if xml =~ /^\s*<[^Hh>]*html/i + webrat_session.response_body = xml + end + + config.before :each do + Webrat.cache_config_for_test + end + + config.after :each do + Webrat.reset_for_test + end +end + +Webrat.configure do |config| + config.mode = :merb +end diff --git a/spec/webrat/core/configuration_spec.rb b/spec/webrat/core/configuration_spec.rb index b03f499..6c22565 100755 --- a/spec/webrat/core/configuration_spec.rb +++ b/spec/webrat/core/configuration_spec.rb @@ -4,14 +4,6 @@ describe Webrat::Configuration do predicate_matchers[:parse_with_nokogiri] = :parse_with_nokogiri? predicate_matchers[:open_error_files] = :open_error_files? - before do - Webrat.cache_config_for_test - end - - after do - Webrat.reset_for_test - end - it "should have a mode" do Webrat.configuration.should respond_to(:mode) end diff --git a/spec/webrat/core/session_spec.rb b/spec/webrat/core/session_spec.rb index c0a5974..013668a 100644 --- a/spec/webrat/core/session_spec.rb +++ b/spec/webrat/core/session_spec.rb @@ -87,12 +87,8 @@ describe Webrat::Session do describe "#request_page" do before(:each) do - Webrat.cache_config_for_test webrat_session = Webrat::Session.new end - after(:each) do - Webrat.reset_for_test - end it "should raise an error if the request is not a success" do webrat_session.stub!(:get) diff --git a/spec/webrat/mechanize/mechanize_session_spec.rb b/spec/webrat/mechanize/mechanize_session_spec.rb index 8afc51f..075d97d 100644 --- a/spec/webrat/mechanize/mechanize_session_spec.rb +++ b/spec/webrat/mechanize/mechanize_session_spec.rb @@ -1,14 +1,11 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') -describe "Webrat::MechanizeSession" do - before :all do - Webrat.cache_config_for_test +require "webrat/mechanize" + +describe Webrat::MechanizeSession do + before :each do Webrat.configuration.mode = :mechanize end - - after :all do - Webrat.reset_for_test - end before(:each) do @mech = Webrat::MechanizeSession.new diff --git a/spec/webrat/merb/helper.rb b/spec/webrat/merb/helper.rb deleted file mode 100644 index 4940bee..0000000 --- a/spec/webrat/merb/helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -require 'merb-core' -require "webrat/merb" \ No newline at end of file diff --git a/spec/webrat/merb/indifferent_access_spec.rb b/spec/webrat/merb/indifferent_access_spec.rb index 9a92c6d..4fe49b0 100644 --- a/spec/webrat/merb/indifferent_access_spec.rb +++ b/spec/webrat/merb/indifferent_access_spec.rb @@ -1,5 +1,4 @@ require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper") -require File.expand_path(File.dirname(__FILE__) + "/helper") describe HashWithIndifferentAccess do it "should not update constructor when not a hash" do diff --git a/spec/webrat/merb/session_spec.rb b/spec/webrat/merb/merb_session_spec.rb similarity index 97% rename from spec/webrat/merb/session_spec.rb rename to spec/webrat/merb/merb_session_spec.rb index fadefa0..6cac7c0 100644 --- a/spec/webrat/merb/session_spec.rb +++ b/spec/webrat/merb/merb_session_spec.rb @@ -2,8 +2,7 @@ require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper") require "webrat/merb" -describe Webrat::Session do - +describe Webrat::MerbSession do it "should not pass empty params if data is and empty hash" do session = Webrat::MerbSession.new response = OpenStruct.new diff --git a/spec/webrat/rails/attaches_file_spec.rb b/spec/webrat/rails/attaches_file_spec.rb index e4b25bd..d03024b 100644 --- a/spec/webrat/rails/attaches_file_spec.rb +++ b/spec/webrat/rails/attaches_file_spec.rb @@ -1,7 +1,8 @@ -require File.expand_path(File.dirname(__FILE__) + '/helper') +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') describe "attach_file" do before do + Webrat.configuration.mode = :rails @filename = __FILE__ @uploaded_file = mock("uploaded file") ActionController::TestUploadedFile.stub!(:new => @uploaded_file) diff --git a/spec/webrat/rails/helper.rb b/spec/webrat/rails/helper.rb deleted file mode 100644 index 14d5790..0000000 --- a/spec/webrat/rails/helper.rb +++ /dev/null @@ -1,10 +0,0 @@ -require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') -require "active_support" - -silence_warnings do - require "action_controller" - require "action_controller/integration" -end - -require "webrat/rails" -Webrat.configuration.mode_for_test = :rails diff --git a/spec/webrat/rails/rails_session_spec.rb b/spec/webrat/rails/rails_session_spec.rb index e8ea061..8bcefdb 100644 --- a/spec/webrat/rails/rails_session_spec.rb +++ b/spec/webrat/rails/rails_session_spec.rb @@ -1,6 +1,12 @@ -require File.expand_path(File.dirname(__FILE__) + '/helper') +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') + +require "webrat/rails" describe Webrat::RailsSession do + before do + Webrat.configuration.mode = :rails + end + it "should delegate response_body to the session response body" do response = mock("response", :body => "") integration_session = mock("integration session", :response => response)