From 7938039548c3269cefe1bc1368f726557793f771 Mon Sep 17 00:00:00 2001 From: Jamis Buck Date: Wed, 19 Jan 2011 10:08:02 -0700 Subject: make TestCaseTest work for pre-1.9 rubies, too --- activesupport/test/test_case_test.rb | 71 +++++++++++++++++++++++------------- 1 file changed, 46 insertions(+), 25 deletions(-) diff --git a/activesupport/test/test_case_test.rb b/activesupport/test/test_case_test.rb index 7e65c63062..b6a96b2ae7 100644 --- a/activesupport/test/test_case_test.rb +++ b/activesupport/test/test_case_test.rb @@ -2,6 +2,8 @@ require 'abstract_unit' module ActiveSupport class TestCaseTest < ActiveSupport::TestCase + IS_MINITEST = defined?(MiniTest::Assertions) && TestCase < MiniTest::Assertions + class FakeRunner attr_reader :puked @@ -12,46 +14,65 @@ module ActiveSupport def puke(klass, name, e) @puked << [klass, name, e] end - end - if defined?(MiniTest::Assertions) && TestCase < MiniTest::Assertions - def test_callback_with_exception - tc = Class.new(TestCase) do - setup :bad_callback - def bad_callback; raise 'oh noes' end - def test_true; assert true end + unless IS_MINITEST + def add_error(e) + puke(nil, nil, e) end - test_name = 'test_true' - fr = FakeRunner.new + def add_run + end - test = tc.new test_name - test.run fr - klass, name, exception = *fr.puked.first + def add_assertion + end + def add_failure(msg, locations=nil) + end + end + end + + def test_callback_with_exception + tc = Class.new(TestCase) do + setup :bad_callback + def bad_callback; raise 'oh noes' end + def test_true; assert true end + end + + test_name = 'test_true' + fr = FakeRunner.new + + test = tc.new test_name + test.run(fr) {} + klass, name, exception = *fr.puked.first + + if IS_MINITEST assert_equal tc, klass assert_equal test_name, name - assert_equal 'oh noes', exception.message end - def test_teardown_callback_with_exception - tc = Class.new(TestCase) do - teardown :bad_callback - def bad_callback; raise 'oh noes' end - def test_true; assert true end - end + assert_match %r{oh noes}, exception.message + end + + def test_teardown_callback_with_exception + tc = Class.new(TestCase) do + teardown :bad_callback + def bad_callback; raise 'oh noes' end + def test_true; assert true end + end - test_name = 'test_true' - fr = FakeRunner.new + test_name = 'test_true' + fr = FakeRunner.new - test = tc.new test_name - test.run fr - klass, name, exception = *fr.puked.first + test = tc.new test_name + test.run(fr) {} + klass, name, exception = *fr.puked.first + if IS_MINITEST assert_equal tc, klass assert_equal test_name, name - assert_equal 'oh noes', exception.message end + + assert_match %r{oh noes}, exception.message end end end -- cgit v1.2.3 From 79a06225ef0e148eb5da541711f74163b5efb18d Mon Sep 17 00:00:00 2001 From: Jamis Buck Date: Wed, 19 Jan 2011 10:08:58 -0700 Subject: scrub instance variables from test cases on teardown this prevents test state from accumulating, resulting in leaked objects and slow tests due to overactive GC. --- activesupport/lib/active_support/test_case.rb | 2 ++ .../lib/active_support/testing/garbage_collection.rb | 19 +++++++++++++++++++ activesupport/test/test_case_test.rb | 18 ++++++++++++++++++ activesupport/test/test_test.rb | 4 ++-- 4 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 activesupport/lib/active_support/testing/garbage_collection.rb diff --git a/activesupport/lib/active_support/test_case.rb b/activesupport/lib/active_support/test_case.rb index fb52fc7083..a7053a1134 100644 --- a/activesupport/lib/active_support/test_case.rb +++ b/activesupport/lib/active_support/test_case.rb @@ -6,6 +6,7 @@ require 'active_support/testing/declarative' require 'active_support/testing/pending' require 'active_support/testing/isolation' require 'active_support/core_ext/kernel/reporting' +require 'active_support/testing/garbage_collection' begin silence_warnings { require 'mocha' } @@ -37,5 +38,6 @@ module ActiveSupport include ActiveSupport::Testing::Deprecation include ActiveSupport::Testing::Pending extend ActiveSupport::Testing::Declarative + include ActiveSupport::Testing::GarbageCollection end end diff --git a/activesupport/lib/active_support/testing/garbage_collection.rb b/activesupport/lib/active_support/testing/garbage_collection.rb new file mode 100644 index 0000000000..7bf9fbafa6 --- /dev/null +++ b/activesupport/lib/active_support/testing/garbage_collection.rb @@ -0,0 +1,19 @@ +module ActiveSupport + module Testing + module GarbageCollection + def self.included(base) + base.teardown :scrub_leftover_instance_variables + end + + private + + RESERVED_INSTANCE_VARIABLES = %w(@test_passed @passed @method_name @__name__ @_result).map(&:to_sym) + + def scrub_leftover_instance_variables + (instance_variables.map(&:to_sym) - RESERVED_INSTANCE_VARIABLES).each do |var| + remove_instance_variable(var) + end + end + end + end +end diff --git a/activesupport/test/test_case_test.rb b/activesupport/test/test_case_test.rb index b6a96b2ae7..740c2351ea 100644 --- a/activesupport/test/test_case_test.rb +++ b/activesupport/test/test_case_test.rb @@ -74,5 +74,23 @@ module ActiveSupport assert_match %r{oh noes}, exception.message end + + def test_teardown_should_scrub_instance_variables + tc = Class.new(TestCase) do + def test_true; @alpha = "a"; assert_equal "a", @alpha; end + end + + test_name = 'test_true' + fr = FakeRunner.new + + test = tc.new test_name + test.run(fr) {} + + passed_var = IS_MINITEST ? :@passed : :@test_passed + ivars = test.instance_variables.map(&:to_sym) + + assert ivars.include?(passed_var), "#{passed_var} should not have been scrubbed" + assert !ivars.include?(:@alpha), "@alpha should have been scrubbed" + end end end diff --git a/activesupport/test/test_test.rb b/activesupport/test/test_test.rb index ee5a20c789..ea652844f5 100644 --- a/activesupport/test/test_test.rb +++ b/activesupport/test/test_test.rb @@ -137,7 +137,7 @@ class SetupAndTeardownTest < ActiveSupport::TestCase def test_inherited_setup_callbacks assert_equal [:reset_callback_record, :foo], self.class._setup_callbacks.map(&:raw_filter) assert_equal [:foo], @called_back - assert_equal [:foo, :sentinel, :foo], self.class._teardown_callbacks.map(&:raw_filter) + assert_equal [:scrub_leftover_instance_variables, :foo, :sentinel, :foo], self.class._teardown_callbacks.map(&:raw_filter) end def setup @@ -169,7 +169,7 @@ class SubclassSetupAndTeardownTest < SetupAndTeardownTest def test_inherited_setup_callbacks assert_equal [:reset_callback_record, :foo, :bar], self.class._setup_callbacks.map(&:raw_filter) assert_equal [:foo, :bar], @called_back - assert_equal [:foo, :sentinel, :foo, :bar], self.class._teardown_callbacks.map(&:raw_filter) + assert_equal [:scrub_leftover_instance_variables, :foo, :sentinel, :foo, :bar], self.class._teardown_callbacks.map(&:raw_filter) end protected -- cgit v1.2.3 From 16a23a184e8b091392c0b6001a025bee8323ec8e Mon Sep 17 00:00:00 2001 From: Jamis Buck Date: Wed, 19 Jan 2011 10:27:53 -0700 Subject: rein in GC during tests by making them run (at most) once per second this can provide a significant performance boost during testing, by preventing the GC from running too frequently. --- .../active_support/testing/garbage_collection.rb | 24 ++++++++++++++++++++++ activesupport/test/test_test.rb | 8 ++++---- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/activesupport/lib/active_support/testing/garbage_collection.rb b/activesupport/lib/active_support/testing/garbage_collection.rb index 7bf9fbafa6..23ac745c3e 100644 --- a/activesupport/lib/active_support/testing/garbage_collection.rb +++ b/activesupport/lib/active_support/testing/garbage_collection.rb @@ -3,6 +3,9 @@ module ActiveSupport module GarbageCollection def self.included(base) base.teardown :scrub_leftover_instance_variables + + base.setup :begin_gc_deferment + base.teardown :reconsider_gc_deferment end private @@ -14,6 +17,27 @@ module ActiveSupport remove_instance_variable(var) end end + + # Minimum interval, in seconds, at which to run GC. Might be less + # frequently than this, if a single test takes longer than this to + # run. + DEFERRED_GC_THRESHOLD = (ENV['DEFERRED_GC_THRESHOLD'] || 1.0).to_f + + @@last_gc_run = Time.now + + def begin_gc_deferment + GC.disable if DEFERRED_GC_THRESHOLD > 0 + end + + def reconsider_gc_deferment + if DEFERRED_GC_THRESHOLD > 0 && Time.now - @@last_gc_run >= DEFERRED_GC_THRESHOLD + GC.enable + GC.start + GC.disable + + @@last_gc_run = Time.now + end + end end end end diff --git a/activesupport/test/test_test.rb b/activesupport/test/test_test.rb index ea652844f5..fa86053301 100644 --- a/activesupport/test/test_test.rb +++ b/activesupport/test/test_test.rb @@ -135,9 +135,9 @@ class SetupAndTeardownTest < ActiveSupport::TestCase teardown :foo, :sentinel, :foo def test_inherited_setup_callbacks - assert_equal [:reset_callback_record, :foo], self.class._setup_callbacks.map(&:raw_filter) + assert_equal [:begin_gc_deferment, :reset_callback_record, :foo], self.class._setup_callbacks.map(&:raw_filter) assert_equal [:foo], @called_back - assert_equal [:scrub_leftover_instance_variables, :foo, :sentinel, :foo], self.class._teardown_callbacks.map(&:raw_filter) + assert_equal [:scrub_leftover_instance_variables, :reconsider_gc_deferment, :foo, :sentinel, :foo], self.class._teardown_callbacks.map(&:raw_filter) end def setup @@ -167,9 +167,9 @@ class SubclassSetupAndTeardownTest < SetupAndTeardownTest teardown :bar def test_inherited_setup_callbacks - assert_equal [:reset_callback_record, :foo, :bar], self.class._setup_callbacks.map(&:raw_filter) + assert_equal [:begin_gc_deferment, :reset_callback_record, :foo, :bar], self.class._setup_callbacks.map(&:raw_filter) assert_equal [:foo, :bar], @called_back - assert_equal [:scrub_leftover_instance_variables, :foo, :sentinel, :foo, :bar], self.class._teardown_callbacks.map(&:raw_filter) + assert_equal [:scrub_leftover_instance_variables, :reconsider_gc_deferment, :foo, :sentinel, :foo, :bar], self.class._teardown_callbacks.map(&:raw_filter) end protected -- cgit v1.2.3 From b247f3944282fb22c68fd4f9248a16fcda63b186 Mon Sep 17 00:00:00 2001 From: Frank Fischer Date: Fri, 14 Jan 2011 09:32:51 +0100 Subject: Added a testcase for bug [#5329] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- .../i18n_test_mailer/mail_with_i18n_subject.erb | 4 ++ actionmailer/test/i18n_with_controller_test.rb | 50 ++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 actionmailer/test/fixtures/i18n_test_mailer/mail_with_i18n_subject.erb create mode 100644 actionmailer/test/i18n_with_controller_test.rb diff --git a/actionmailer/test/fixtures/i18n_test_mailer/mail_with_i18n_subject.erb b/actionmailer/test/fixtures/i18n_test_mailer/mail_with_i18n_subject.erb new file mode 100644 index 0000000000..f5340283f1 --- /dev/null +++ b/actionmailer/test/fixtures/i18n_test_mailer/mail_with_i18n_subject.erb @@ -0,0 +1,4 @@ +Hello there, + +Mr. <%= @recipient %>. Be greeted, new member! + diff --git a/actionmailer/test/i18n_with_controller_test.rb b/actionmailer/test/i18n_with_controller_test.rb new file mode 100644 index 0000000000..759c007c45 --- /dev/null +++ b/actionmailer/test/i18n_with_controller_test.rb @@ -0,0 +1,50 @@ +require 'abstract_unit' +require 'action_controller' + +class I18nTestMailer < ActionMailer::Base + + configure do |c| + c.assets_dir = '' # To get the tests to pass + end + + def mail_with_i18n_subject(recipient) + @recipient = recipient + I18n.locale = :de + mail(:to => recipient, :subject => "#{I18n.t :email_subject} #{recipient}", + :from => "system@loudthinking.com", :date => Time.local(2004, 12, 12)) + end +end + +class TestController < ActionController::Base + def send_mail + I18nTestMailer.mail_with_i18n_subject(@recipient).deliver + render :text => 'Mail sent' + end +end + +class ActionMailerI18nWithControllerTest < ActionDispatch::IntegrationTest + + Routes = ActionDispatch::Routing::RouteSet.new + Routes.draw do + match ':controller(/:action(/:id))' + end + + def app + Routes + end + + def setup + I18n.backend.store_translations('de', :email_subject => '[Signed up] Welcome') + set_delivery_method :test + ActionMailer::Base.perform_deliveries = true + ActionMailer::Base.deliveries.clear + ActiveSupport::Deprecation.silenced = false + + @recipient = 'test@localhost' + end + + def test_send_mail + get '/test/send_mail' + assert_equal "Mail sent", @response.body + end +end -- cgit v1.2.3 From 262b2ea8cda20999ddf8c4bf13b7a70453e996d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 19 Jan 2011 23:42:10 +0100 Subject: Solve SystemStackError when changing locale inside ActionMailer [#5329 state:resolved] --- actionmailer/test/i18n_with_controller_test.rb | 16 ++++++---------- actionpack/lib/abstract_controller/rendering.rb | 9 +++++---- actionpack/lib/action_view/lookup_context.rb | 4 ++-- actionpack/test/template/lookup_context_test.rb | 2 +- 4 files changed, 14 insertions(+), 17 deletions(-) diff --git a/actionmailer/test/i18n_with_controller_test.rb b/actionmailer/test/i18n_with_controller_test.rb index 759c007c45..7040ae6f8d 100644 --- a/actionmailer/test/i18n_with_controller_test.rb +++ b/actionmailer/test/i18n_with_controller_test.rb @@ -2,13 +2,12 @@ require 'abstract_unit' require 'action_controller' class I18nTestMailer < ActionMailer::Base - configure do |c| - c.assets_dir = '' # To get the tests to pass + c.assets_dir = '' end def mail_with_i18n_subject(recipient) - @recipient = recipient + @recipient = recipient I18n.locale = :de mail(:to => recipient, :subject => "#{I18n.t :email_subject} #{recipient}", :from => "system@loudthinking.com", :date => Time.local(2004, 12, 12)) @@ -17,13 +16,12 @@ end class TestController < ActionController::Base def send_mail - I18nTestMailer.mail_with_i18n_subject(@recipient).deliver + I18nTestMailer.mail_with_i18n_subject("test@localhost").deliver render :text => 'Mail sent' end end class ActionMailerI18nWithControllerTest < ActionDispatch::IntegrationTest - Routes = ActionDispatch::Routing::RouteSet.new Routes.draw do match ':controller(/:action(/:id))' @@ -35,12 +33,10 @@ class ActionMailerI18nWithControllerTest < ActionDispatch::IntegrationTest def setup I18n.backend.store_translations('de', :email_subject => '[Signed up] Welcome') - set_delivery_method :test - ActionMailer::Base.perform_deliveries = true - ActionMailer::Base.deliveries.clear - ActiveSupport::Deprecation.silenced = false + end - @recipient = 'test@localhost' + def teardown + I18n.locale = :en end def test_send_mail diff --git a/actionpack/lib/abstract_controller/rendering.rb b/actionpack/lib/abstract_controller/rendering.rb index 9b912ea988..ec1160c31e 100644 --- a/actionpack/lib/abstract_controller/rendering.rb +++ b/actionpack/lib/abstract_controller/rendering.rb @@ -13,14 +13,15 @@ module AbstractController # This is a class to fix I18n global state. Whenever you provide I18n.locale during a request, # it will trigger the lookup_context and consequently expire the cache. class I18nProxy < ::I18n::Config #:nodoc: - attr_reader :i18n_config, :lookup_context + attr_reader :original_config, :lookup_context - def initialize(i18n_config, lookup_context) - @i18n_config, @lookup_context = i18n_config, lookup_context + def initialize(original_config, lookup_context) + original_config = original_config.original_config if original_config.respond_to?(:original_config) + @original_config, @lookup_context = original_config, lookup_context end def locale - @i18n_config.locale + @original_config.locale end def locale=(value) diff --git a/actionpack/lib/action_view/lookup_context.rb b/actionpack/lib/action_view/lookup_context.rb index 1365048724..e434f3b059 100644 --- a/actionpack/lib/action_view/lookup_context.rb +++ b/actionpack/lib/action_view/lookup_context.rb @@ -186,11 +186,11 @@ module ActionView end # Overload locale= to also set the I18n.locale. If the current I18n.config object responds - # to i18n_config, it means that it's has a copy of the original I18n configuration and it's + # to original_config, it means that it's has a copy of the original I18n configuration and it's # acting as proxy, which we need to skip. def locale=(value) if value - config = I18n.config.respond_to?(:i18n_config) ? I18n.config.i18n_config : I18n.config + config = I18n.config.respond_to?(:original_config) ? I18n.config.original_config : I18n.config config.locale = value end diff --git a/actionpack/test/template/lookup_context_test.rb b/actionpack/test/template/lookup_context_test.rb index f7a684779c..f3b1335000 100644 --- a/actionpack/test/template/lookup_context_test.rb +++ b/actionpack/test/template/lookup_context_test.rb @@ -73,7 +73,7 @@ class LookupContextTest < ActiveSupport::TestCase assert_equal :pt, I18n.locale assert_equal :pt, @lookup_context.locale ensure - I18n.config = I18n.config.i18n_config + I18n.config = I18n.config.original_config end assert_equal :pt, I18n.locale -- cgit v1.2.3 From 41f76946d02e571a2483eccb72632960125e122b Mon Sep 17 00:00:00 2001 From: Jamis Buck Date: Wed, 19 Jan 2011 15:55:23 -0700 Subject: Revert "rein in GC during tests by making them run (at most) once per second" This reverts commit 16a23a184e8b091392c0b6001a025bee8323ec8e. --- .../active_support/testing/garbage_collection.rb | 24 ---------------------- activesupport/test/test_test.rb | 8 ++++---- 2 files changed, 4 insertions(+), 28 deletions(-) diff --git a/activesupport/lib/active_support/testing/garbage_collection.rb b/activesupport/lib/active_support/testing/garbage_collection.rb index 23ac745c3e..7bf9fbafa6 100644 --- a/activesupport/lib/active_support/testing/garbage_collection.rb +++ b/activesupport/lib/active_support/testing/garbage_collection.rb @@ -3,9 +3,6 @@ module ActiveSupport module GarbageCollection def self.included(base) base.teardown :scrub_leftover_instance_variables - - base.setup :begin_gc_deferment - base.teardown :reconsider_gc_deferment end private @@ -17,27 +14,6 @@ module ActiveSupport remove_instance_variable(var) end end - - # Minimum interval, in seconds, at which to run GC. Might be less - # frequently than this, if a single test takes longer than this to - # run. - DEFERRED_GC_THRESHOLD = (ENV['DEFERRED_GC_THRESHOLD'] || 1.0).to_f - - @@last_gc_run = Time.now - - def begin_gc_deferment - GC.disable if DEFERRED_GC_THRESHOLD > 0 - end - - def reconsider_gc_deferment - if DEFERRED_GC_THRESHOLD > 0 && Time.now - @@last_gc_run >= DEFERRED_GC_THRESHOLD - GC.enable - GC.start - GC.disable - - @@last_gc_run = Time.now - end - end end end end diff --git a/activesupport/test/test_test.rb b/activesupport/test/test_test.rb index fa86053301..ea652844f5 100644 --- a/activesupport/test/test_test.rb +++ b/activesupport/test/test_test.rb @@ -135,9 +135,9 @@ class SetupAndTeardownTest < ActiveSupport::TestCase teardown :foo, :sentinel, :foo def test_inherited_setup_callbacks - assert_equal [:begin_gc_deferment, :reset_callback_record, :foo], self.class._setup_callbacks.map(&:raw_filter) + assert_equal [:reset_callback_record, :foo], self.class._setup_callbacks.map(&:raw_filter) assert_equal [:foo], @called_back - assert_equal [:scrub_leftover_instance_variables, :reconsider_gc_deferment, :foo, :sentinel, :foo], self.class._teardown_callbacks.map(&:raw_filter) + assert_equal [:scrub_leftover_instance_variables, :foo, :sentinel, :foo], self.class._teardown_callbacks.map(&:raw_filter) end def setup @@ -167,9 +167,9 @@ class SubclassSetupAndTeardownTest < SetupAndTeardownTest teardown :bar def test_inherited_setup_callbacks - assert_equal [:begin_gc_deferment, :reset_callback_record, :foo, :bar], self.class._setup_callbacks.map(&:raw_filter) + assert_equal [:reset_callback_record, :foo, :bar], self.class._setup_callbacks.map(&:raw_filter) assert_equal [:foo, :bar], @called_back - assert_equal [:scrub_leftover_instance_variables, :reconsider_gc_deferment, :foo, :sentinel, :foo, :bar], self.class._teardown_callbacks.map(&:raw_filter) + assert_equal [:scrub_leftover_instance_variables, :foo, :sentinel, :foo, :bar], self.class._teardown_callbacks.map(&:raw_filter) end protected -- cgit v1.2.3 From 1de1dc02d7e7920bd243da6910baa3cac7002926 Mon Sep 17 00:00:00 2001 From: Jamis Buck Date: Wed, 19 Jan 2011 15:55:30 -0700 Subject: Revert "scrub instance variables from test cases on teardown" This reverts commit 79a06225ef0e148eb5da541711f74163b5efb18d. --- activesupport/lib/active_support/test_case.rb | 2 -- .../lib/active_support/testing/garbage_collection.rb | 19 ------------------- activesupport/test/test_case_test.rb | 18 ------------------ activesupport/test/test_test.rb | 4 ++-- 4 files changed, 2 insertions(+), 41 deletions(-) delete mode 100644 activesupport/lib/active_support/testing/garbage_collection.rb diff --git a/activesupport/lib/active_support/test_case.rb b/activesupport/lib/active_support/test_case.rb index a7053a1134..fb52fc7083 100644 --- a/activesupport/lib/active_support/test_case.rb +++ b/activesupport/lib/active_support/test_case.rb @@ -6,7 +6,6 @@ require 'active_support/testing/declarative' require 'active_support/testing/pending' require 'active_support/testing/isolation' require 'active_support/core_ext/kernel/reporting' -require 'active_support/testing/garbage_collection' begin silence_warnings { require 'mocha' } @@ -38,6 +37,5 @@ module ActiveSupport include ActiveSupport::Testing::Deprecation include ActiveSupport::Testing::Pending extend ActiveSupport::Testing::Declarative - include ActiveSupport::Testing::GarbageCollection end end diff --git a/activesupport/lib/active_support/testing/garbage_collection.rb b/activesupport/lib/active_support/testing/garbage_collection.rb deleted file mode 100644 index 7bf9fbafa6..0000000000 --- a/activesupport/lib/active_support/testing/garbage_collection.rb +++ /dev/null @@ -1,19 +0,0 @@ -module ActiveSupport - module Testing - module GarbageCollection - def self.included(base) - base.teardown :scrub_leftover_instance_variables - end - - private - - RESERVED_INSTANCE_VARIABLES = %w(@test_passed @passed @method_name @__name__ @_result).map(&:to_sym) - - def scrub_leftover_instance_variables - (instance_variables.map(&:to_sym) - RESERVED_INSTANCE_VARIABLES).each do |var| - remove_instance_variable(var) - end - end - end - end -end diff --git a/activesupport/test/test_case_test.rb b/activesupport/test/test_case_test.rb index 740c2351ea..b6a96b2ae7 100644 --- a/activesupport/test/test_case_test.rb +++ b/activesupport/test/test_case_test.rb @@ -74,23 +74,5 @@ module ActiveSupport assert_match %r{oh noes}, exception.message end - - def test_teardown_should_scrub_instance_variables - tc = Class.new(TestCase) do - def test_true; @alpha = "a"; assert_equal "a", @alpha; end - end - - test_name = 'test_true' - fr = FakeRunner.new - - test = tc.new test_name - test.run(fr) {} - - passed_var = IS_MINITEST ? :@passed : :@test_passed - ivars = test.instance_variables.map(&:to_sym) - - assert ivars.include?(passed_var), "#{passed_var} should not have been scrubbed" - assert !ivars.include?(:@alpha), "@alpha should have been scrubbed" - end end end diff --git a/activesupport/test/test_test.rb b/activesupport/test/test_test.rb index ea652844f5..ee5a20c789 100644 --- a/activesupport/test/test_test.rb +++ b/activesupport/test/test_test.rb @@ -137,7 +137,7 @@ class SetupAndTeardownTest < ActiveSupport::TestCase def test_inherited_setup_callbacks assert_equal [:reset_callback_record, :foo], self.class._setup_callbacks.map(&:raw_filter) assert_equal [:foo], @called_back - assert_equal [:scrub_leftover_instance_variables, :foo, :sentinel, :foo], self.class._teardown_callbacks.map(&:raw_filter) + assert_equal [:foo, :sentinel, :foo], self.class._teardown_callbacks.map(&:raw_filter) end def setup @@ -169,7 +169,7 @@ class SubclassSetupAndTeardownTest < SetupAndTeardownTest def test_inherited_setup_callbacks assert_equal [:reset_callback_record, :foo, :bar], self.class._setup_callbacks.map(&:raw_filter) assert_equal [:foo, :bar], @called_back - assert_equal [:scrub_leftover_instance_variables, :foo, :sentinel, :foo, :bar], self.class._teardown_callbacks.map(&:raw_filter) + assert_equal [:foo, :sentinel, :foo, :bar], self.class._teardown_callbacks.map(&:raw_filter) end protected -- cgit v1.2.3 From bc9b1075aec2a63f789b105cd11886a2c8c45ccf Mon Sep 17 00:00:00 2001 From: Jamis Buck Date: Wed, 19 Jan 2011 15:55:32 -0700 Subject: Revert "make TestCaseTest work for pre-1.9 rubies, too" This reverts commit 7938039548c3269cefe1bc1368f726557793f771. --- activesupport/test/test_case_test.rb | 71 +++++++++++++----------------------- 1 file changed, 25 insertions(+), 46 deletions(-) diff --git a/activesupport/test/test_case_test.rb b/activesupport/test/test_case_test.rb index b6a96b2ae7..7e65c63062 100644 --- a/activesupport/test/test_case_test.rb +++ b/activesupport/test/test_case_test.rb @@ -2,8 +2,6 @@ require 'abstract_unit' module ActiveSupport class TestCaseTest < ActiveSupport::TestCase - IS_MINITEST = defined?(MiniTest::Assertions) && TestCase < MiniTest::Assertions - class FakeRunner attr_reader :puked @@ -14,65 +12,46 @@ module ActiveSupport def puke(klass, name, e) @puked << [klass, name, e] end - - unless IS_MINITEST - def add_error(e) - puke(nil, nil, e) - end - - def add_run - end - - def add_assertion - end - - def add_failure(msg, locations=nil) - end - end end - def test_callback_with_exception - tc = Class.new(TestCase) do - setup :bad_callback - def bad_callback; raise 'oh noes' end - def test_true; assert true end - end + if defined?(MiniTest::Assertions) && TestCase < MiniTest::Assertions + def test_callback_with_exception + tc = Class.new(TestCase) do + setup :bad_callback + def bad_callback; raise 'oh noes' end + def test_true; assert true end + end - test_name = 'test_true' - fr = FakeRunner.new + test_name = 'test_true' + fr = FakeRunner.new - test = tc.new test_name - test.run(fr) {} - klass, name, exception = *fr.puked.first + test = tc.new test_name + test.run fr + klass, name, exception = *fr.puked.first - if IS_MINITEST assert_equal tc, klass assert_equal test_name, name + assert_equal 'oh noes', exception.message end - assert_match %r{oh noes}, exception.message - end - - def test_teardown_callback_with_exception - tc = Class.new(TestCase) do - teardown :bad_callback - def bad_callback; raise 'oh noes' end - def test_true; assert true end - end + def test_teardown_callback_with_exception + tc = Class.new(TestCase) do + teardown :bad_callback + def bad_callback; raise 'oh noes' end + def test_true; assert true end + end - test_name = 'test_true' - fr = FakeRunner.new + test_name = 'test_true' + fr = FakeRunner.new - test = tc.new test_name - test.run(fr) {} - klass, name, exception = *fr.puked.first + test = tc.new test_name + test.run fr + klass, name, exception = *fr.puked.first - if IS_MINITEST assert_equal tc, klass assert_equal test_name, name + assert_equal 'oh noes', exception.message end - - assert_match %r{oh noes}, exception.message end end end -- cgit v1.2.3