From 7b28a55a2bc9bedd5a8c8dec0a8a02166927ef16 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Tue, 10 Jun 2008 14:01:05 -0700 Subject: Remove direct TestCase mixins. Add miniunit compatibility. --- activesupport/lib/active_support/test_case.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'activesupport/lib/active_support/test_case.rb') diff --git a/activesupport/lib/active_support/test_case.rb b/activesupport/lib/active_support/test_case.rb index 197e73b3e8..cdd884f918 100644 --- a/activesupport/lib/active_support/test_case.rb +++ b/activesupport/lib/active_support/test_case.rb @@ -1,10 +1,14 @@ require 'test/unit/testcase' +require 'active_support/testing/setup_and_teardown' +require 'active_support/testing/assertions' require 'active_support/testing/default' -require 'active_support/testing/core_ext/test' - module ActiveSupport - class TestCase < Test::Unit::TestCase + class TestCase < ::Test::Unit::TestCase + include ActiveSupport::Testing::SetupAndTeardown + include ActiveSupport::Testing::Assertions + include ActiveSupport::Testing::Default + # test "verify something" do # ... # end -- cgit v1.2.3 From 18099b0fd53b8f9ba88ef46bdd910347f03c72c5 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Fri, 7 Nov 2008 12:45:48 -0500 Subject: Rework testing extensions to reflect the recent miniunit upheaval --- activesupport/lib/active_support/test_case.rb | 44 +++++++++++++++------------ 1 file changed, 24 insertions(+), 20 deletions(-) (limited to 'activesupport/lib/active_support/test_case.rb') diff --git a/activesupport/lib/active_support/test_case.rb b/activesupport/lib/active_support/test_case.rb index cdd884f918..be38eb64a1 100644 --- a/activesupport/lib/active_support/test_case.rb +++ b/activesupport/lib/active_support/test_case.rb @@ -1,28 +1,32 @@ -require 'test/unit/testcase' require 'active_support/testing/setup_and_teardown' require 'active_support/testing/assertions' -require 'active_support/testing/default' +require 'active_support/testing/declarative' module ActiveSupport - class TestCase < ::Test::Unit::TestCase - include ActiveSupport::Testing::SetupAndTeardown - include ActiveSupport::Testing::Assertions - include ActiveSupport::Testing::Default + # Prefer MiniTest with Test::Unit compatibility. + # Hacks around the test/unit autorun. + begin + require 'minitest/unit' + MiniTest::Unit.disable_autorun + require 'test/unit' + + class TestCase < ::Test::Unit::TestCase + @@installed_at_exit = false + end + + # Test::Unit compatibility. + rescue LoadError + require 'test/unit/testcase' + require 'active_support/testing/default' - # test "verify something" do - # ... - # end - def self.test(name, &block) - test_name = "test_#{name.gsub(/\s+/,'_')}".to_sym - defined = instance_method(test_name) rescue false - raise "#{test_name} is already defined in #{self}" if defined - if block_given? - define_method(test_name, &block) - else - define_method(test_name) do - flunk "No implementation provided for #{name}" - end - end + class TestCase < ::Test::Unit::TestCase + include ActiveSupport::Testing::Default end end + + class TestCase + include ActiveSupport::Testing::SetupAndTeardown + include ActiveSupport::Testing::Assertions + extend ActiveSupport::Testing::Declarative + end end -- cgit v1.2.3 From 70c2fcab09334b0bdbc58e67ff3cf7f1de472112 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Fri, 7 Nov 2008 12:58:42 -0500 Subject: Safer but hacky minitest autorun override --- activesupport/lib/active_support/test_case.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'activesupport/lib/active_support/test_case.rb') diff --git a/activesupport/lib/active_support/test_case.rb b/activesupport/lib/active_support/test_case.rb index be38eb64a1..b991f62a17 100644 --- a/activesupport/lib/active_support/test_case.rb +++ b/activesupport/lib/active_support/test_case.rb @@ -4,15 +4,16 @@ require 'active_support/testing/declarative' module ActiveSupport # Prefer MiniTest with Test::Unit compatibility. - # Hacks around the test/unit autorun. begin require 'minitest/unit' + + # Hack around the test/unit autorun. + autorun_enabled = MiniTest::Unit.class_variable_get('@@installed_at_exit') MiniTest::Unit.disable_autorun require 'test/unit' + MiniTest::Unit.class_variable_set('@@installed_at_exit', autorun_enabled) - class TestCase < ::Test::Unit::TestCase - @@installed_at_exit = false - end + class TestCase < ::Test::Unit::TestCase; end # Test::Unit compatibility. rescue LoadError -- cgit v1.2.3 From 00f72cf99d3653198a1e080964d396fbeb23e52e Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Fri, 7 Nov 2008 13:26:28 -0500 Subject: Set AS::TestCase::Assertion to the underlying test exception for either miniunit or test/unit --- activesupport/lib/active_support/test_case.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'activesupport/lib/active_support/test_case.rb') diff --git a/activesupport/lib/active_support/test_case.rb b/activesupport/lib/active_support/test_case.rb index b991f62a17..f47329d026 100644 --- a/activesupport/lib/active_support/test_case.rb +++ b/activesupport/lib/active_support/test_case.rb @@ -13,7 +13,9 @@ module ActiveSupport require 'test/unit' MiniTest::Unit.class_variable_set('@@installed_at_exit', autorun_enabled) - class TestCase < ::Test::Unit::TestCase; end + class TestCase < ::Test::Unit::TestCase + Assertion = MiniTest::Assertion + end # Test::Unit compatibility. rescue LoadError @@ -21,6 +23,7 @@ module ActiveSupport require 'active_support/testing/default' class TestCase < ::Test::Unit::TestCase + Assertion = Test::Unit::AssertionFailedError include ActiveSupport::Testing::Default end end -- cgit v1.2.3 From 3a33ee28e9babc5a1a78079f5ca50ea6249f2643 Mon Sep 17 00:00:00 2001 From: "Hongli Lai (Phusion)" Date: Mon, 17 Nov 2008 21:28:43 +0100 Subject: Fix compatibility with Ruby 1.8 that also has the Miniunit gem installed. Signed-off-by: Jeremy Kemper --- activesupport/lib/active_support/test_case.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'activesupport/lib/active_support/test_case.rb') diff --git a/activesupport/lib/active_support/test_case.rb b/activesupport/lib/active_support/test_case.rb index f47329d026..5b825b212d 100644 --- a/activesupport/lib/active_support/test_case.rb +++ b/activesupport/lib/active_support/test_case.rb @@ -8,10 +8,14 @@ module ActiveSupport require 'minitest/unit' # Hack around the test/unit autorun. - autorun_enabled = MiniTest::Unit.class_variable_get('@@installed_at_exit') - MiniTest::Unit.disable_autorun + autorun_enabled = MiniTest::Unit.send(:class_variable_get, '@@installed_at_exit') + if MiniTest::Unit.respond_to?(:disable_autorun) + MiniTest::Unit.disable_autorun + else + MiniTest::Unit.send(:class_variable_set, '@@installed_at_exit', false) + end require 'test/unit' - MiniTest::Unit.class_variable_set('@@installed_at_exit', autorun_enabled) + MiniTest::Unit.send(:class_variable_set, '@@installed_at_exit', autorun_enabled) class TestCase < ::Test::Unit::TestCase Assertion = MiniTest::Assertion -- cgit v1.2.3 From f42c77f927eb49b00e84d355e07de48723d03fcb Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sat, 22 Nov 2008 18:06:08 +0100 Subject: Added ActiveSupport::BacktraceCleaner and Rails::BacktraceCleaner for cutting down on backtrace noise (inspired by the Thoughtbot Quiet Backtrace plugin) [DHH] --- activesupport/lib/active_support/test_case.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'activesupport/lib/active_support/test_case.rb') diff --git a/activesupport/lib/active_support/test_case.rb b/activesupport/lib/active_support/test_case.rb index 5b825b212d..d1e657c15f 100644 --- a/activesupport/lib/active_support/test_case.rb +++ b/activesupport/lib/active_support/test_case.rb @@ -21,15 +21,21 @@ module ActiveSupport Assertion = MiniTest::Assertion end + # TODO: Figure out how to get the Rails::BacktraceFilter into minitest/unit # Test::Unit compatibility. rescue LoadError require 'test/unit/testcase' require 'active_support/testing/default' + if defined?(Rails) + require 'rails/backtrace_cleaner' + Test::Unit::Util::BacktraceFilter.module_eval { include Rails::BacktraceFilterForTestUnit } + end + class TestCase < ::Test::Unit::TestCase Assertion = Test::Unit::AssertionFailedError include ActiveSupport::Testing::Default - end + end end class TestCase @@ -37,4 +43,4 @@ module ActiveSupport include ActiveSupport::Testing::Assertions extend ActiveSupport::Testing::Declarative end -end +end \ No newline at end of file -- cgit v1.2.3 From e7208d382a3d8bae9ab13d8a380b1a2a05fd99b0 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sat, 22 Nov 2008 19:18:30 -0800 Subject: Get ActiveSupport::TestCase working with classic Test::Unit and MiniTest. Fix broken Mocha + MiniTest. Assume ruby-core applies patch #771 fixing libraries which extend Test::Unit. --- activesupport/lib/active_support/test_case.rb | 56 ++++++++++++--------------- 1 file changed, 25 insertions(+), 31 deletions(-) (limited to 'activesupport/lib/active_support/test_case.rb') diff --git a/activesupport/lib/active_support/test_case.rb b/activesupport/lib/active_support/test_case.rb index d1e657c15f..a4a45079fa 100644 --- a/activesupport/lib/active_support/test_case.rb +++ b/activesupport/lib/active_support/test_case.rb @@ -1,46 +1,40 @@ +require 'test/unit/testcase' require 'active_support/testing/setup_and_teardown' require 'active_support/testing/assertions' require 'active_support/testing/declarative' -module ActiveSupport - # Prefer MiniTest with Test::Unit compatibility. - begin - require 'minitest/unit' +begin + gem 'mocha', '>= 0.9.0' + require 'mocha' - # Hack around the test/unit autorun. - autorun_enabled = MiniTest::Unit.send(:class_variable_get, '@@installed_at_exit') - if MiniTest::Unit.respond_to?(:disable_autorun) - MiniTest::Unit.disable_autorun - else - MiniTest::Unit.send(:class_variable_set, '@@installed_at_exit', false) - end - require 'test/unit' - MiniTest::Unit.send(:class_variable_set, '@@installed_at_exit', autorun_enabled) + if defined?(MiniTest) + require 'active_support/testing/mocha_minitest_adapter' + end +rescue LoadError + # Fake Mocha::ExpectationError so we can rescue it in #run. Bleh. + Object.const_set :Mocha, Module.new + Mocha.const_set :ExpectationError, Class.new(StandardError) +end - class TestCase < ::Test::Unit::TestCase +module ActiveSupport + class TestCase < ::Test::Unit::TestCase + if defined? MiniTest Assertion = MiniTest::Assertion - end - - # TODO: Figure out how to get the Rails::BacktraceFilter into minitest/unit - # Test::Unit compatibility. - rescue LoadError - require 'test/unit/testcase' - require 'active_support/testing/default' - - if defined?(Rails) - require 'rails/backtrace_cleaner' - Test::Unit::Util::BacktraceFilter.module_eval { include Rails::BacktraceFilterForTestUnit } - end + else + # TODO: Figure out how to get the Rails::BacktraceFilter into minitest/unit + if defined?(Rails) + require 'rails/backtrace_cleaner' + Test::Unit::Util::BacktraceFilter.module_eval { include Rails::BacktraceFilterForTestUnit } + end - class TestCase < ::Test::Unit::TestCase Assertion = Test::Unit::AssertionFailedError + + require 'active_support/testing/default' include ActiveSupport::Testing::Default - end - end + end - class TestCase include ActiveSupport::Testing::SetupAndTeardown include ActiveSupport::Testing::Assertions extend ActiveSupport::Testing::Declarative end -end \ No newline at end of file +end -- cgit v1.2.3 From 9d4ae40bb40b2354c4061a23ae4db9a28e3174e6 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sun, 23 Nov 2008 13:11:07 -0800 Subject: Move deprecation assertions so TestCase (and Mocha) needn't load on startup --- activesupport/lib/active_support/test_case.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'activesupport/lib/active_support/test_case.rb') diff --git a/activesupport/lib/active_support/test_case.rb b/activesupport/lib/active_support/test_case.rb index a4a45079fa..90c6aff215 100644 --- a/activesupport/lib/active_support/test_case.rb +++ b/activesupport/lib/active_support/test_case.rb @@ -1,6 +1,7 @@ require 'test/unit/testcase' require 'active_support/testing/setup_and_teardown' require 'active_support/testing/assertions' +require 'active_support/testing/deprecation' require 'active_support/testing/declarative' begin @@ -35,6 +36,7 @@ module ActiveSupport include ActiveSupport::Testing::SetupAndTeardown include ActiveSupport::Testing::Assertions + include ActiveSupport::Testing::Deprecation extend ActiveSupport::Testing::Declarative end end -- cgit v1.2.3 From e931012287df0bca83cae04d95c2e0835ae08758 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sun, 23 Nov 2008 14:48:36 -0800 Subject: Require Mocha >= 0.9.3 which includes a MiniTest adapter --- activesupport/lib/active_support/test_case.rb | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'activesupport/lib/active_support/test_case.rb') diff --git a/activesupport/lib/active_support/test_case.rb b/activesupport/lib/active_support/test_case.rb index 90c6aff215..1cc8564a18 100644 --- a/activesupport/lib/active_support/test_case.rb +++ b/activesupport/lib/active_support/test_case.rb @@ -1,22 +1,18 @@ -require 'test/unit/testcase' -require 'active_support/testing/setup_and_teardown' -require 'active_support/testing/assertions' -require 'active_support/testing/deprecation' -require 'active_support/testing/declarative' - begin - gem 'mocha', '>= 0.9.0' + gem 'mocha', '>= 0.9.3' require 'mocha' - - if defined?(MiniTest) - require 'active_support/testing/mocha_minitest_adapter' - end rescue LoadError # Fake Mocha::ExpectationError so we can rescue it in #run. Bleh. Object.const_set :Mocha, Module.new Mocha.const_set :ExpectationError, Class.new(StandardError) end +require 'test/unit/testcase' +require 'active_support/testing/setup_and_teardown' +require 'active_support/testing/assertions' +require 'active_support/testing/deprecation' +require 'active_support/testing/declarative' + module ActiveSupport class TestCase < ::Test::Unit::TestCase if defined? MiniTest -- cgit v1.2.3 From 5fa8c3b6db48c0be923e4572468493f162551336 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 26 Nov 2008 17:20:05 -0800 Subject: MiniTest::Unit#method_name alias for Test::Unit compat --- activesupport/lib/active_support/test_case.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'activesupport/lib/active_support/test_case.rb') diff --git a/activesupport/lib/active_support/test_case.rb b/activesupport/lib/active_support/test_case.rb index 1cc8564a18..97b2b6ef9c 100644 --- a/activesupport/lib/active_support/test_case.rb +++ b/activesupport/lib/active_support/test_case.rb @@ -17,6 +17,7 @@ module ActiveSupport class TestCase < ::Test::Unit::TestCase if defined? MiniTest Assertion = MiniTest::Assertion + alias_method :method_name, :name else # TODO: Figure out how to get the Rails::BacktraceFilter into minitest/unit if defined?(Rails) -- cgit v1.2.3