Module | ActiveSupport::Testing |
In: |
vendor/rails/activesupport/lib/active_support/testing/default.rb
vendor/rails/activesupport/lib/active_support/testing/setup_and_teardown.rb |
# File vendor/rails/activesupport/lib/active_support/testing/setup_and_teardown.rb, line 12 12: def self.included(base) 13: base.send :include, ActiveSupport::Callbacks 14: base.define_callbacks :setup, :teardown 15: 16: begin 17: require 'mocha' 18: base.alias_method_chain :run, :callbacks_and_mocha 19: rescue LoadError 20: base.alias_method_chain :run, :callbacks 21: end 22: end
Doubly unfortunate: mocha does the same so we have to hax their hax.
# File vendor/rails/activesupport/lib/active_support/testing/setup_and_teardown.rb, line 57 57: def run_with_callbacks_and_mocha(result) 58: return if @method_name.to_s == "default_test" 59: 60: yield(Test::Unit::TestCase::STARTED, name) 61: @_result = result 62: begin 63: mocha_setup 64: begin 65: run_callbacks :setup 66: setup 67: __send__(@method_name) 68: mocha_verify { add_assertion } 69: rescue Mocha::ExpectationError => e 70: add_failure(e.message, e.backtrace) 71: rescue Test::Unit::AssertionFailedError => e 72: add_failure(e.message, e.backtrace) 73: rescue StandardError, ScriptError 74: add_error($!) 75: ensure 76: begin 77: teardown 78: run_callbacks :teardown, :enumerator => :reverse_each 79: rescue Test::Unit::AssertionFailedError => e 80: add_failure(e.message, e.backtrace) 81: rescue StandardError, ScriptError 82: add_error($!) 83: end 84: end 85: ensure 86: mocha_teardown 87: end 88: result.add_run 89: yield(Test::Unit::TestCase::FINISHED, name) 90: end