use stubbing instead of monkeypatching to stop tests from interfering with one another. Closes #11163 [RubyRedRick]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8899 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
Michael Koziarski 2008-02-19 21:43:13 +00:00
parent e32149ad60
commit 1537aec184
1 changed files with 13 additions and 14 deletions

View File

@ -3,23 +3,21 @@ require 'action_controller/integration'
uses_mocha 'integration' do uses_mocha 'integration' do
# Stub process for testing. module IntegrationSessionStubbing
module ActionController def stub_integration_session(session)
module Integration session.stubs(:process)
class Session session.stubs(:generic_url_rewriter)
def process(*args)
end
def generic_url_rewriter
end
end
end end
end end
class SessionTest < Test::Unit::TestCase class SessionTest < Test::Unit::TestCase
include IntegrationSessionStubbing
def setup def setup
@session = ActionController::Integration::Session.new @session = ActionController::Integration::Session.new
stub_integration_session(@session)
end end
def test_https_bang_works_and_sets_truth_by_default def test_https_bang_works_and_sets_truth_by_default
assert !@session.https? assert !@session.https?
@session.https! @session.https!
@ -210,11 +208,13 @@ class SessionTest < Test::Unit::TestCase
end end
class IntegrationTestTest < Test::Unit::TestCase class IntegrationTestTest < Test::Unit::TestCase
include IntegrationSessionStubbing
def setup def setup
@test = ::ActionController::IntegrationTest.new(:default_test) @test = ::ActionController::IntegrationTest.new(:default_test)
@test.class.stubs(:fixture_table_names).returns([]) @test.class.stubs(:fixture_table_names).returns([])
@session = @test.open_session @session = @test.open_session
stub_integration_session(@session)
end end
def test_opens_new_session def test_opens_new_session
@ -233,12 +233,15 @@ end
# Tests that integration tests don't call Controller test methods for processing. # Tests that integration tests don't call Controller test methods for processing.
# Integration tests have their own setup and teardown. # Integration tests have their own setup and teardown.
class IntegrationTestUsesCorrectClass < ActionController::IntegrationTest class IntegrationTestUsesCorrectClass < ActionController::IntegrationTest
include IntegrationSessionStubbing
def self.fixture_table_names def self.fixture_table_names
[] []
end end
def test_integration_methods_called def test_integration_methods_called
reset!
stub_integration_session(@integration_session)
%w( get post head put delete ).each do |verb| %w( get post head put delete ).each do |verb|
assert_nothing_raised("'#{verb}' should use integration test methods") { send!(verb, '/') } assert_nothing_raised("'#{verb}' should use integration test methods") { send!(verb, '/') }
end end
@ -246,8 +249,4 @@ class IntegrationTestUsesCorrectClass < ActionController::IntegrationTest
end end
# TODO
# class MockCGITest < Test::Unit::TestCase
# end
end # uses_mocha end # uses_mocha