1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
require 'mocha/integration/assertion_counter'
require 'mocha/integration/monkey_patcher'
require 'mocha/expectation_error'
module Mocha
module Integration
module TestUnit
module GemVersion200
def self.applicable_to?(test_unit_version, ruby_version = nil)
Gem::Requirement.new('2.0.0').satisfied_by?(test_unit_version)
end
def self.description
"monkey patch for Test::Unit gem v2.0.0"
end
def self.included(mod)
MonkeyPatcher.apply(mod, RunMethodPatch)
end
module RunMethodPatch
def run(result)
assertion_counter = AssertionCounter.new(self)
begin
@_result = result
yield(Test::Unit::TestCase::STARTED, name)
begin
begin
run_setup
__send__(@method_name)
mocha_verify(assertion_counter)
rescue Mocha::ExpectationError => e
add_failure(e.message, e.backtrace)
rescue Exception
@interrupted = true
raise unless handle_exception($!)
ensure
begin
run_teardown
rescue Mocha::ExpectationError => e
add_failure(e.message, e.backtrace)
rescue Exception
raise unless handle_exception($!)
end
end
ensure
mocha_teardown
end
result.add_run
yield(Test::Unit::TestCase::FINISHED, name)
ensure
@_result = nil
end
end
end
end
end
end
end
|