diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2008-11-07 12:45:48 -0500 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2008-11-07 12:45:48 -0500 |
commit | 18099b0fd53b8f9ba88ef46bdd910347f03c72c5 (patch) | |
tree | 763fef4bb4966040d2b80c19301bf9572feb02db /activesupport/lib | |
parent | 7b28a55a2bc9bedd5a8c8dec0a8a02166927ef16 (diff) | |
download | rails-18099b0fd53b8f9ba88ef46bdd910347f03c72c5.tar.gz rails-18099b0fd53b8f9ba88ef46bdd910347f03c72c5.tar.bz2 rails-18099b0fd53b8f9ba88ef46bdd910347f03c72c5.zip |
Rework testing extensions to reflect the recent miniunit upheaval
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/test_case.rb | 44 | ||||
-rw-r--r-- | activesupport/lib/active_support/testing/assertions.rb | 2 | ||||
-rw-r--r-- | activesupport/lib/active_support/testing/setup_and_teardown.rb | 28 |
3 files changed, 39 insertions, 35 deletions
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 diff --git a/activesupport/lib/active_support/testing/assertions.rb b/activesupport/lib/active_support/testing/assertions.rb index 7665d9217e..ce2f44efd6 100644 --- a/activesupport/lib/active_support/testing/assertions.rb +++ b/activesupport/lib/active_support/testing/assertions.rb @@ -32,7 +32,7 @@ module ActiveSupport # post :delete, :id => ... # end def assert_difference(expressions, difference = 1, message = nil, &block) - expression_evaluations = Array(expressions).collect{ |expression| lambda { eval(expression, block.send!(:binding)) } } + expression_evaluations = Array(expressions).collect{ |expression| lambda { eval(expression, block.send(:binding)) } } original_values = expression_evaluations.inject([]) { |memo, expression| memo << expression.call } yield diff --git a/activesupport/lib/active_support/testing/setup_and_teardown.rb b/activesupport/lib/active_support/testing/setup_and_teardown.rb index a514b61fea..c70e149c16 100644 --- a/activesupport/lib/active_support/testing/setup_and_teardown.rb +++ b/activesupport/lib/active_support/testing/setup_and_teardown.rb @@ -14,9 +14,8 @@ module ActiveSupport include ActiveSupport::Callbacks define_callbacks :setup, :teardown - if defined?(::Mini) - undef_method :run - alias_method :run, :run_with_callbacks_and_miniunit + if defined?(::MiniTest) + include ForMiniTest else begin require 'mocha' @@ -30,22 +29,23 @@ module ActiveSupport end end - def run_with_callbacks_and_miniunit(runner) - result = '.' - begin - run_callbacks :setup - result = super - rescue Exception => e - result = runner.puke(self.class, self.name, e) - ensure + module ForMiniTest + def run(runner) + result = '.' begin - teardown - run_callbacks :teardown, :enumerator => :reverse_each + run_callbacks :setup + result = super rescue Exception => e result = runner.puke(self.class, self.name, e) + ensure + begin + run_callbacks :teardown, :enumerator => :reverse_each + rescue Exception => e + result = runner.puke(self.class, self.name, e) + end end + result end - result end # This redefinition is unfortunate but test/unit shows us no alternative. |