Permalink
Browse files

Rubinious: setup/teardown override for miniunit

  • Loading branch information...
1 parent f5cbad2 commit 34c51c9e8f758a5fc892e654b6ca1ad8b86d1b3a @jeremy jeremy committed Jun 10, 2008
Showing with 31 additions and 7 deletions.
  1. +31 −7 activesupport/lib/active_support/testing/setup_and_teardown.rb
@@ -10,19 +10,43 @@ module SetupAndTeardown
end
def self.included(base)
- base.send :include, ActiveSupport::Callbacks
- base.define_callbacks :setup, :teardown
+ base.class_eval do
+ include ActiveSupport::Callbacks
+ define_callbacks :setup, :teardown
+ if defined?(::Mini)
+ alias_method :run, :run_with_callbacks_and_miniunit
+ else
+ begin
+ require 'mocha'
+ alias_method :run, :run_with_callbacks_and_mocha
+ rescue LoadError
+ alias_method :run, :run_with_callbacks_and_testunit
+ end
+ end
+ end
+ end
+
+ def run_with_callbacks_and_miniunit(runner)
+ result = '.'
begin
- require 'mocha'
- base.alias_method_chain :run, :callbacks_and_mocha
- rescue LoadError
- base.alias_method_chain :run, :callbacks
+ run_callbacks :setup
+ result = super
+ rescue Exception => e
+ result = runner.puke(self.class, self.name, e)
+ ensure
+ begin
+ teardown
+ run_callbacks :teardown, :enumerator => :reverse_each
+ rescue Exception => e
+ result = runner.puke(self.class, self.name, e)
+ end
end
+ result
end
# This redefinition is unfortunate but test/unit shows us no alternative.
- def run_with_callbacks(result) #:nodoc:
+ def run_with_callbacks_and_testunit(result) #:nodoc:
return if @method_name.to_s == "default_test"
yield(Test::Unit::TestCase::STARTED, name)

1 comment on commit 34c51c9

@jduff
Contributor
jduff commented on 34c51c9 Jan 9, 2009

So if you have mocha installed run_with_callbacks_and_mocha gets called, even if you’re not using mocha?

Please sign in to comment.