From b9f6affa3f44b766c3fe6f657d3e099b1592d87f Mon Sep 17 00:00:00 2001 From: Gwyn Morfey Date: Fri, 18 Apr 2008 13:37:03 +0100 Subject: [PATCH] All but 3 merb tests pass --- test/checks_test.rb | 4 ++-- test/chooses_test.rb | 2 +- test/clicks_button_test.rb | 2 +- test/clicks_link_test.rb | 2 +- test/fills_in_test.rb | 2 +- test/helper.rb | 37 +++++++++---------------------------- test/reloads_test.rb | 2 +- test/selects_test.rb | 2 +- test/visits_test.rb | 21 ++++++--------------- 9 files changed, 23 insertions(+), 51 deletions(-) diff --git a/test/checks_test.rb b/test/checks_test.rb index 7d3113b..56f4432 100644 --- a/test/checks_test.rb +++ b/test/checks_test.rb @@ -2,7 +2,7 @@ require File.dirname(__FILE__) + "/helper" class ChecksTest < Test::Unit::TestCase def setup - @session = ActionController::Integration::Session.new + @session = test_session @session.stubs(:assert_response) @session.stubs(:get_via_redirect) @session.stubs(:response).returns(@response=mock) @@ -72,7 +72,7 @@ end class UnchecksTest < Test::Unit::TestCase def setup - @session = ActionController::Integration::Session.new + @session = test_session @session.stubs(:assert_response) @session.stubs(:get_via_redirect) @session.stubs(:response).returns(@response=mock) diff --git a/test/chooses_test.rb b/test/chooses_test.rb index 6b9afa8..cd5097e 100644 --- a/test/chooses_test.rb +++ b/test/chooses_test.rb @@ -3,7 +3,7 @@ require File.dirname(__FILE__) + "/helper" class ChoosesTest < Test::Unit::TestCase def setup - @session = ActionController::Integration::Session.new + @session = test_session @session.stubs(:assert_response) @session.stubs(:get_via_redirect) @session.stubs(:response).returns(@response=mock) diff --git a/test/clicks_button_test.rb b/test/clicks_button_test.rb index 26a8b9a..4239b2e 100644 --- a/test/clicks_button_test.rb +++ b/test/clicks_button_test.rb @@ -2,7 +2,7 @@ require File.dirname(__FILE__) + "/helper" class ClicksButtonTest < Test::Unit::TestCase def setup - @session = ActionController::Integration::Session.new + @session = test_session @session.stubs(:assert_response) @session.stubs(:get_via_redirect) @page = Webrat::Page.new(@session) diff --git a/test/clicks_link_test.rb b/test/clicks_link_test.rb index 3b1c7e9..7ed2db6 100644 --- a/test/clicks_link_test.rb +++ b/test/clicks_link_test.rb @@ -2,7 +2,7 @@ require File.dirname(__FILE__) + "/helper" class ClicksLinkTest < Test::Unit::TestCase def setup - @session = ActionController::Integration::Session.new + @session = test_session @session.stubs(:assert_response) @session.stubs(:get_via_redirect) @session.stubs(:response).returns(@response=mock) diff --git a/test/fills_in_test.rb b/test/fills_in_test.rb index 19daf3f..aba64c8 100644 --- a/test/fills_in_test.rb +++ b/test/fills_in_test.rb @@ -2,7 +2,7 @@ require File.dirname(__FILE__) + "/helper" class FillsInTest < Test::Unit::TestCase def setup - @session = ActionController::Integration::Session.new + @session = test_session @session.stubs(:assert_response) @session.stubs(:get_via_redirect) @session.stubs(:response).returns(@response=mock) diff --git a/test/helper.rb b/test/helper.rb index 35550ce..8b6224b 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -5,35 +5,16 @@ require "mocha" # gem install redgreen for colored test output begin require "redgreen" unless ENV['TM_CURRENT_LINE']; rescue LoadError; end -if ENV["TEST_MODE"] == "rails" - require "active_support" - silence_warnings do - require "action_controller" - require "action_controller/integration" - end - - class ActionController::Integration::Session - def flunk(message) - raise message - end - end - -elsif ENV["TEST_MODE"] == "merb" - require 'merb-core' - require 'merb_stories' - #require 'spec' #makes mocha cry - module Merb - module Test - class RspecStory - include Merb::Test::ControllerHelper - include Merb::Test::RouteHelper - include Merb::Test::ViewHelper - end - end - end - +if ["rails","merb"].include?(ENV["TEST_MODE"]) + require File.join(File.dirname(__FILE__), "helper_#{ENV["TEST_MODE"]}.rb") else raise "Please set the environment variable TEST_MODE to either 'rails' or 'merb'." end - + require File.expand_path(File.dirname(__FILE__) + "/../lib/webrat") + +def test_session + return ActionController::Integration::Session.new if ENV["TEST_MODE"] == "rails" + return Merb::Test::RspecStory.new if ENV["TEST_MODE"] == "merb" + raise "Unknown test type #{ENV["TEST_MODE"]}" +end \ No newline at end of file diff --git a/test/reloads_test.rb b/test/reloads_test.rb index 1f3e1ff..a69c330 100644 --- a/test/reloads_test.rb +++ b/test/reloads_test.rb @@ -5,7 +5,7 @@ RAILS_ROOT = "." unless defined?(RAILS_ROOT) class ReloadsTest < Test::Unit::TestCase def setup - @session = ActionController::Integration::Session.new + @session = test_session @session.stubs(:assert_response) @session.stubs(:get_via_redirect) @response = mock diff --git a/test/selects_test.rb b/test/selects_test.rb index 05576c4..cc26f37 100644 --- a/test/selects_test.rb +++ b/test/selects_test.rb @@ -2,7 +2,7 @@ require File.dirname(__FILE__) + "/helper" class SelectsTest < Test::Unit::TestCase def setup - @session = ActionController::Integration::Session.new + @session = test_session @session.stubs(:assert_response) @session.stubs(:get_via_redirect) @session.stubs(:response).returns(@response=mock) diff --git a/test/visits_test.rb b/test/visits_test.rb index d497892..a17cf54 100644 --- a/test/visits_test.rb +++ b/test/visits_test.rb @@ -5,21 +5,12 @@ RAILS_ROOT = "." unless defined?(RAILS_ROOT) class VisitsTest < Test::Unit::TestCase def setup - if ENV["TEST_MODE"] == "rails" - @session = ActionController::Integration::Session.new - @session.stubs(:assert_response) - @session.stubs(:get_via_redirect) - @response = mock - @session.stubs(:response).returns(@response) - @response.stubs(:body).returns("") - elsif ENV["TEST_MODE"] == "merb" - @session = Merb::Test::RspecStory.new - @session.stubs(:assert_response) - @session.stubs(:get_via_redirect) - @response = mock - @session.stubs(:response).returns(@response) - @response.stubs(:body).returns("") - end + @session = test_session + @session.stubs(:assert_response) + @session.stubs(:get_via_redirect) + @response = mock + @session.stubs(:response).returns(@response) + @response.stubs(:body).returns("") end def test_should_use_get