mocha 0.12.10 → 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.yardopts +22 -0
- data/COPYING.md +3 -0
- data/{MIT-LICENSE.rdoc → MIT-LICENSE.md} +0 -0
- data/README.md +230 -0
- data/{RELEASE.rdoc → RELEASE.md} +61 -56
- data/Rakefile +45 -37
- data/build-matrix.rb +16 -4
- data/lib/mocha.rb +6 -2
- data/lib/mocha/api.rb +13 -16
- data/lib/mocha/class_method.rb +7 -3
- data/lib/mocha/class_methods.rb +63 -0
- data/lib/mocha/debug.rb +11 -0
- data/lib/mocha/deprecation.rb +1 -1
- data/lib/mocha/exception_raiser.rb +1 -1
- data/lib/mocha/expectation_error.rb +5 -0
- data/lib/mocha/expectation_error_factory.rb +19 -0
- data/lib/mocha/hooks.rb +43 -0
- data/lib/mocha/integration.rb +6 -38
- data/lib/mocha/integration/assertion_counter.rb +13 -0
- data/lib/mocha/integration/mini_test.rb +42 -60
- data/lib/mocha/integration/mini_test/adapter.rb +54 -0
- data/lib/mocha/integration/mini_test/exception_translation.rb +0 -6
- data/lib/mocha/integration/mini_test/nothing.rb +19 -0
- data/lib/mocha/integration/mini_test/version_13.rb +32 -25
- data/lib/mocha/integration/mini_test/version_140.rb +32 -26
- data/lib/mocha/integration/mini_test/version_141.rb +40 -34
- data/lib/mocha/integration/mini_test/version_142_to_172.rb +40 -34
- data/lib/mocha/integration/mini_test/version_200.rb +41 -35
- data/lib/mocha/integration/mini_test/version_201_to_222.rb +41 -35
- data/lib/mocha/integration/mini_test/version_2110_to_2111.rb +49 -43
- data/lib/mocha/integration/mini_test/version_2112_to_320.rb +53 -47
- data/lib/mocha/integration/mini_test/version_230_to_2101.rb +43 -37
- data/lib/mocha/integration/monkey_patcher.rb +18 -0
- data/lib/mocha/integration/test_unit.rb +38 -45
- data/lib/mocha/integration/test_unit/adapter.rb +51 -0
- data/lib/mocha/integration/test_unit/gem_version_200.rb +36 -29
- data/lib/mocha/integration/test_unit/gem_version_201_to_202.rb +36 -29
- data/lib/mocha/integration/test_unit/gem_version_203_to_220.rb +36 -29
- data/lib/mocha/integration/test_unit/gem_version_230_to_250.rb +65 -0
- data/lib/mocha/integration/test_unit/nothing.rb +19 -0
- data/lib/mocha/integration/test_unit/ruby_version_185_and_below.rb +36 -29
- data/lib/mocha/integration/test_unit/ruby_version_186_and_above.rb +37 -30
- data/lib/mocha/method_matcher.rb +1 -1
- data/lib/mocha/module_methods.rb +14 -0
- data/lib/mocha/{object.rb → object_methods.rb} +0 -83
- data/lib/mocha/setup.rb +10 -0
- data/lib/mocha/standalone.rb +3 -0
- data/lib/mocha/version.rb +1 -1
- data/lib/mocha_standalone.rb +3 -1
- data/mocha.gemspec +16 -9
- data/test/acceptance/bug_18914_test.rb +1 -1
- data/test/acceptance/bug_21465_test.rb +1 -1
- data/test/acceptance/bug_21563_test.rb +1 -1
- data/test/acceptance/exception_rescue_test.rb +1 -1
- data/test/acceptance/expectations_on_multiple_methods_test.rb +1 -1
- data/test/acceptance/expected_invocation_count_test.rb +1 -1
- data/test/acceptance/failure_messages_test.rb +1 -1
- data/test/acceptance/issue_65_test.rb +1 -1
- data/test/acceptance/issue_70_test.rb +1 -1
- data/test/acceptance/mocha_example_test.rb +1 -1
- data/test/acceptance/mocha_test_result_test.rb +1 -1
- data/test/acceptance/mock_test.rb +1 -1
- data/test/acceptance/mock_with_initializer_block_test.rb +1 -1
- data/test/acceptance/mocked_methods_dispatch_test.rb +1 -1
- data/test/acceptance/multiple_expectations_failure_message_test.rb +1 -1
- data/test/acceptance/optional_parameters_test.rb +1 -1
- data/test/acceptance/parameter_matcher_test.rb +1 -1
- data/test/acceptance/partial_mocks_test.rb +1 -1
- data/test/acceptance/raise_exception_test.rb +1 -1
- data/test/acceptance/return_value_test.rb +1 -1
- data/test/acceptance/sequence_test.rb +1 -1
- data/test/acceptance/states_test.rb +1 -1
- data/test/acceptance/stub_any_instance_method_test.rb +1 -1
- data/test/acceptance/stub_class_method_defined_on_active_record_association_proxy_test.rb +1 -1
- data/test/acceptance/stub_class_method_defined_on_class_test.rb +1 -1
- data/test/acceptance/stub_class_method_defined_on_module_test.rb +1 -1
- data/test/acceptance/stub_class_method_defined_on_superclass_test.rb +1 -1
- data/test/acceptance/stub_everything_test.rb +1 -1
- data/test/acceptance/stub_instance_method_defined_on_active_record_association_proxy_test.rb +1 -1
- data/test/acceptance/stub_instance_method_defined_on_class_and_aliased_test.rb +1 -1
- data/test/acceptance/stub_instance_method_defined_on_class_test.rb +1 -1
- data/test/acceptance/stub_instance_method_defined_on_kernel_module_test.rb +1 -1
- data/test/acceptance/stub_instance_method_defined_on_module_test.rb +1 -1
- data/test/acceptance/stub_instance_method_defined_on_object_class_test.rb +1 -1
- data/test/acceptance/stub_instance_method_defined_on_singleton_class_test.rb +1 -1
- data/test/acceptance/stub_instance_method_defined_on_superclass_test.rb +1 -1
- data/test/acceptance/stub_module_method_test.rb +1 -1
- data/test/acceptance/stub_test.rb +1 -1
- data/test/acceptance/stubba_example_test.rb +1 -1
- data/test/acceptance/stubba_test_result_test.rb +1 -1
- data/test/acceptance/stubbing_error_backtrace_test.rb +1 -1
- data/test/acceptance/stubbing_frozen_object_test.rb +1 -1
- data/test/acceptance/stubbing_method_accepting_block_parameter_test.rb +1 -1
- data/test/acceptance/stubbing_method_unnecessarily_test.rb +1 -1
- data/test/acceptance/stubbing_nil_test.rb +1 -1
- data/test/acceptance/stubbing_non_existent_any_instance_method_test.rb +1 -1
- data/test/acceptance/stubbing_non_existent_class_method_test.rb +1 -1
- data/test/acceptance/stubbing_non_existent_instance_method_test.rb +1 -1
- data/test/acceptance/stubbing_non_public_any_instance_method_test.rb +1 -1
- data/test/acceptance/stubbing_non_public_class_method_test.rb +1 -1
- data/test/acceptance/stubbing_non_public_instance_method_test.rb +1 -1
- data/test/acceptance/stubbing_on_non_mock_object_test.rb +1 -1
- data/test/acceptance/stubbing_same_class_method_on_parent_and_child_classes_test.rb +3 -3
- data/test/acceptance/throw_test.rb +1 -1
- data/test/acceptance/unstubbing_test.rb +1 -1
- data/test/integration/mini_test_test.rb +9 -0
- data/test/integration/shared_tests.rb +174 -0
- data/test/integration/test_unit_test.rb +9 -0
- data/test/mini_test_result.rb +0 -1
- data/test/test_runner.rb +14 -14
- data/test/unit/class_methods_test.rb +40 -0
- data/test/unit/method_matcher_test.rb +5 -0
- data/test/unit/mock_test.rb +6 -0
- data/test/unit/module_methods_test.rb +19 -0
- data/test/unit/object_methods_test.rb +45 -0
- metadata +45 -74
- data/COPYING.rdoc +0 -3
- data/README.rdoc +0 -56
- data/examples/misc.rb +0 -43
- data/examples/mocha.rb +0 -25
- data/examples/stubba.rb +0 -64
- data/gemfiles/Gemfile.minitest.3.3.0 +0 -7
- data/gemfiles/Gemfile.minitest.4.2.0 +0 -7
- data/lib/mocha/integration/mini_test/assertion_counter.rb +0 -23
- data/lib/mocha/integration/mini_test/version_330_to_410.rb +0 -65
- data/lib/mocha/integration/mini_test/version_420_to_433.rb +0 -70
- data/lib/mocha/integration/mini_test/version_440.rb +0 -70
- data/lib/mocha/integration/mini_test/version_450_to_461.rb +0 -72
- data/lib/mocha/integration/test_unit/assertion_counter.rb +0 -23
- data/lib/mocha/integration/test_unit/gem_version_230_to_254.rb +0 -58
- data/lib/mocha/options.rb +0 -1
- data/test/acceptance/api_test.rb +0 -139
- data/test/acceptance/minitest_test.rb +0 -162
- data/test/unit/object_test.rb +0 -92
@@ -1,59 +1,65 @@
|
|
1
|
-
require 'mocha/integration/
|
2
|
-
require 'mocha/
|
1
|
+
require 'mocha/integration/assertion_counter'
|
2
|
+
require 'mocha/integration/monkey_patcher'
|
3
|
+
require 'mocha/integration/mini_test/exception_translation'
|
3
4
|
|
4
5
|
module Mocha
|
5
|
-
|
6
6
|
module Integration
|
7
|
-
|
8
7
|
module MiniTest
|
9
|
-
|
10
8
|
module Version230To2101
|
9
|
+
def self.applicable_to?(mini_test_version)
|
10
|
+
Gem::Requirement.new('>= 2.3.0', '<= 2.10.1').satisfied_by?(mini_test_version)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.description
|
14
|
+
"monkey patch for MiniTest gem >= v2.3.0 <= v2.10.1"
|
15
|
+
end
|
16
|
+
|
11
17
|
def self.included(mod)
|
12
|
-
|
18
|
+
MonkeyPatcher.apply(mod, RunMethodPatch)
|
13
19
|
end
|
14
|
-
def run runner
|
15
|
-
trap 'INFO' do
|
16
|
-
time = runner.start_time ? Time.now - runner.start_time : 0
|
17
|
-
warn "%s#%s %.2fs" % [self.class, self.__name__, time]
|
18
|
-
runner.status $stderr
|
19
|
-
end if ::MiniTest::Unit::TestCase::SUPPORTS_INFO_SIGNAL
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
module RunMethodPatch
|
22
|
+
def run runner
|
23
|
+
trap 'INFO' do
|
24
|
+
time = runner.start_time ? Time.now - runner.start_time : 0
|
25
|
+
warn "%s#%s %.2fs" % [self.class, self.__name__, time]
|
26
|
+
runner.status $stderr
|
27
|
+
end if ::MiniTest::Unit::TestCase::SUPPORTS_INFO_SIGNAL
|
28
|
+
|
29
|
+
assertion_counter = AssertionCounter.new(self)
|
30
|
+
result = ""
|
24
31
|
begin
|
25
|
-
@passed = nil
|
26
|
-
self.setup
|
27
|
-
self.run_setup_hooks
|
28
|
-
self.__send__ self.__name__
|
29
|
-
mocha_verify(assertion_counter)
|
30
|
-
result = "." unless io?
|
31
|
-
@passed = true
|
32
|
-
rescue *::MiniTest::Unit::TestCase::PASSTHROUGH_EXCEPTIONS
|
33
|
-
raise
|
34
|
-
rescue Exception => e
|
35
|
-
@passed = false
|
36
|
-
result = runner.puke self.class, self.__name__, Mocha::Integration::MiniTest.translate(e)
|
37
|
-
ensure
|
38
32
|
begin
|
39
|
-
|
40
|
-
self.
|
33
|
+
@passed = nil
|
34
|
+
self.setup
|
35
|
+
self.run_setup_hooks
|
36
|
+
self.__send__ self.__name__
|
37
|
+
mocha_verify(assertion_counter)
|
38
|
+
result = "." unless io?
|
39
|
+
@passed = true
|
41
40
|
rescue *::MiniTest::Unit::TestCase::PASSTHROUGH_EXCEPTIONS
|
42
41
|
raise
|
43
42
|
rescue Exception => e
|
43
|
+
@passed = false
|
44
44
|
result = runner.puke self.class, self.__name__, Mocha::Integration::MiniTest.translate(e)
|
45
|
+
ensure
|
46
|
+
begin
|
47
|
+
self.run_teardown_hooks
|
48
|
+
self.teardown
|
49
|
+
rescue *::MiniTest::Unit::TestCase::PASSTHROUGH_EXCEPTIONS
|
50
|
+
raise
|
51
|
+
rescue Exception => e
|
52
|
+
result = runner.puke self.class, self.__name__, Mocha::Integration::MiniTest.translate(e)
|
53
|
+
end
|
54
|
+
trap 'INFO', 'DEFAULT' if ::MiniTest::Unit::TestCase::SUPPORTS_INFO_SIGNAL
|
45
55
|
end
|
46
|
-
|
56
|
+
ensure
|
57
|
+
mocha_teardown
|
47
58
|
end
|
48
|
-
|
49
|
-
mocha_teardown
|
59
|
+
result
|
50
60
|
end
|
51
|
-
result
|
52
61
|
end
|
53
62
|
end
|
54
|
-
|
55
63
|
end
|
56
|
-
|
57
64
|
end
|
58
|
-
|
59
65
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'mocha/api'
|
2
|
+
|
3
|
+
module Mocha
|
4
|
+
module Integration
|
5
|
+
module MonkeyPatcher
|
6
|
+
def self.apply(mod, run_method_patch)
|
7
|
+
unless mod < Mocha::API
|
8
|
+
mod.send(:include, Mocha::API)
|
9
|
+
end
|
10
|
+
unless mod.method_defined?(:run_before_mocha)
|
11
|
+
mod.send(:alias_method, :run_before_mocha, :run)
|
12
|
+
mod.send(:remove_method, :run)
|
13
|
+
mod.send(:include, run_method_patch)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -1,56 +1,49 @@
|
|
1
|
-
require 'mocha/
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
module
|
14
|
-
module
|
15
|
-
|
16
|
-
|
17
|
-
include Mocha::API
|
18
|
-
|
19
|
-
alias_method :run_before_mocha, :run
|
20
|
-
remove_method :run
|
1
|
+
require 'mocha/debug'
|
2
|
+
|
3
|
+
require 'mocha/integration/test_unit/nothing'
|
4
|
+
require 'mocha/integration/test_unit/ruby_version_185_and_below'
|
5
|
+
require 'mocha/integration/test_unit/ruby_version_186_and_above'
|
6
|
+
require 'mocha/integration/test_unit/gem_version_200'
|
7
|
+
require 'mocha/integration/test_unit/gem_version_201_to_202'
|
8
|
+
require 'mocha/integration/test_unit/gem_version_203_to_220'
|
9
|
+
require 'mocha/integration/test_unit/gem_version_230_to_250'
|
10
|
+
require 'mocha/integration/test_unit/adapter'
|
11
|
+
|
12
|
+
module Mocha
|
13
|
+
module Integration
|
14
|
+
module TestUnit
|
15
|
+
def self.activate
|
16
|
+
return false unless defined?(::Test::Unit::TestCase) && !(defined?(::MiniTest::Unit::TestCase) && (::Test::Unit::TestCase < ::MiniTest::Unit::TestCase))
|
21
17
|
|
22
18
|
test_unit_version = begin
|
23
19
|
load 'test/unit/version.rb'
|
24
|
-
Gem::Version.new(Test::Unit::VERSION)
|
20
|
+
Gem::Version.new(::Test::Unit::VERSION)
|
25
21
|
rescue LoadError
|
26
|
-
Gem::Version.new('1.
|
22
|
+
Gem::Version.new('1.0.0')
|
27
23
|
end
|
28
24
|
|
29
|
-
|
30
|
-
|
31
|
-
|
25
|
+
ruby_version = Gem::Version.new(RUBY_VERSION.dup)
|
26
|
+
|
27
|
+
Debug.puts "Detected Ruby version: #{ruby_version}"
|
28
|
+
Debug.puts "Detected Test::Unit version: #{test_unit_version}"
|
29
|
+
|
30
|
+
integration_module = [
|
31
|
+
TestUnit::Adapter,
|
32
|
+
TestUnit::GemVersion230To250,
|
33
|
+
TestUnit::GemVersion203To220,
|
34
|
+
TestUnit::GemVersion201To202,
|
35
|
+
TestUnit::GemVersion200,
|
36
|
+
TestUnit::RubyVersion186AndAbove,
|
37
|
+
TestUnit::RubyVersion185AndBelow,
|
38
|
+
TestUnit::Nothing
|
39
|
+
].detect { |m| m.applicable_to?(test_unit_version, ruby_version) }
|
40
|
+
|
41
|
+
unless ::Test::Unit::TestCase < integration_module
|
42
|
+
Debug.puts "Applying #{integration_module.description}"
|
43
|
+
::Test::Unit::TestCase.send(:include, integration_module)
|
32
44
|
end
|
33
|
-
|
34
|
-
if (test_unit_version == Gem::Version.new('1.x')) || (test_unit_version == Gem::Version.new('1.2.3'))
|
35
|
-
if RUBY_VERSION < '1.8.6'
|
36
|
-
include Mocha::Integration::TestUnit::RubyVersion185AndBelow
|
37
|
-
else
|
38
|
-
include Mocha::Integration::TestUnit::RubyVersion186AndAbove
|
39
|
-
end
|
40
|
-
elsif Gem::Requirement.new('2.0.0').satisfied_by?(test_unit_version)
|
41
|
-
include Mocha::Integration::TestUnit::GemVersion200
|
42
|
-
elsif Gem::Requirement.new('>= 2.0.1', '<= 2.0.2').satisfied_by?(test_unit_version)
|
43
|
-
include Mocha::Integration::TestUnit::GemVersion201To202
|
44
|
-
elsif Gem::Requirement.new('>= 2.0.3', '<= 2.2.0').satisfied_by?(test_unit_version)
|
45
|
-
include Mocha::Integration::TestUnit::GemVersion203To220
|
46
|
-
elsif Gem::Requirement.new('>= 2.3.0', '<= 2.5.4').satisfied_by?(test_unit_version)
|
47
|
-
include Mocha::Integration::TestUnit::GemVersion230To254
|
48
|
-
else
|
49
|
-
raise "No Mocha monkey-patch for Test::Unit version"
|
50
|
-
end
|
51
|
-
|
45
|
+
true
|
52
46
|
end
|
53
47
|
end
|
54
48
|
end
|
55
|
-
|
56
49
|
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'mocha/api'
|
2
|
+
require 'mocha/integration/assertion_counter'
|
3
|
+
require 'mocha/expectation_error'
|
4
|
+
|
5
|
+
module Mocha
|
6
|
+
module Integration
|
7
|
+
module TestUnit
|
8
|
+
|
9
|
+
# Integrates Mocha into recent versions of Test::Unit.
|
10
|
+
#
|
11
|
+
# See the source code for an example of how to integrate Mocha into a test library.
|
12
|
+
module Adapter
|
13
|
+
include Mocha::API
|
14
|
+
|
15
|
+
# @private
|
16
|
+
def self.applicable_to?(test_unit_version, ruby_version = nil)
|
17
|
+
Gem::Requirement.new('>= 2.5.1').satisfied_by?(test_unit_version)
|
18
|
+
end
|
19
|
+
|
20
|
+
# @private
|
21
|
+
def self.description
|
22
|
+
"adapter for Test::Unit gem >= v2.5.1"
|
23
|
+
end
|
24
|
+
|
25
|
+
# @private
|
26
|
+
def self.included(mod)
|
27
|
+
mod.setup :mocha_setup, :before => :prepend
|
28
|
+
|
29
|
+
mod.exception_handler(:handle_mocha_expectation_error)
|
30
|
+
|
31
|
+
mod.cleanup :after => :append do
|
32
|
+
assertion_counter = Integration::AssertionCounter.new(self)
|
33
|
+
mocha_verify(assertion_counter)
|
34
|
+
end
|
35
|
+
|
36
|
+
mod.teardown :mocha_teardown, :after => :append
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
# @private
|
42
|
+
def handle_mocha_expectation_error(e)
|
43
|
+
return false unless e.is_a?(Mocha::ExpectationError)
|
44
|
+
problem_occurred
|
45
|
+
add_failure(e.message, e.backtrace)
|
46
|
+
true
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -1,52 +1,59 @@
|
|
1
|
-
require '
|
2
|
-
require 'mocha/integration/
|
1
|
+
require 'mocha/integration/assertion_counter'
|
2
|
+
require 'mocha/integration/monkey_patcher'
|
3
3
|
require 'mocha/expectation_error'
|
4
4
|
|
5
5
|
module Mocha
|
6
|
-
|
7
6
|
module Integration
|
8
|
-
|
9
7
|
module TestUnit
|
10
|
-
|
11
8
|
module GemVersion200
|
9
|
+
def self.applicable_to?(test_unit_version, ruby_version = nil)
|
10
|
+
Gem::Requirement.new('2.0.0').satisfied_by?(test_unit_version)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.description
|
14
|
+
"monkey patch for Test::Unit gem v2.0.0"
|
15
|
+
end
|
16
|
+
|
12
17
|
def self.included(mod)
|
13
|
-
|
18
|
+
MonkeyPatcher.apply(mod, RunMethodPatch)
|
14
19
|
end
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
yield(Test::Unit::TestCase::STARTED, name)
|
20
|
+
|
21
|
+
module RunMethodPatch
|
22
|
+
def run(result)
|
23
|
+
assertion_counter = AssertionCounter.new(self)
|
20
24
|
begin
|
25
|
+
@_result = result
|
26
|
+
yield(Test::Unit::TestCase::STARTED, name)
|
21
27
|
begin
|
22
|
-
run_setup
|
23
|
-
__send__(@method_name)
|
24
|
-
mocha_verify(assertion_counter)
|
25
|
-
rescue Mocha::ExpectationError => e
|
26
|
-
add_failure(e.message, e.backtrace)
|
27
|
-
rescue Exception
|
28
|
-
@interrupted = true
|
29
|
-
raise unless handle_exception($!)
|
30
|
-
ensure
|
31
28
|
begin
|
32
|
-
|
29
|
+
run_setup
|
30
|
+
__send__(@method_name)
|
31
|
+
mocha_verify(assertion_counter)
|
32
|
+
rescue Mocha::ExpectationError => e
|
33
|
+
add_failure(e.message, e.backtrace)
|
33
34
|
rescue Exception
|
35
|
+
@interrupted = true
|
34
36
|
raise unless handle_exception($!)
|
37
|
+
ensure
|
38
|
+
begin
|
39
|
+
run_teardown
|
40
|
+
rescue Mocha::ExpectationError => e
|
41
|
+
add_failure(e.message, e.backtrace)
|
42
|
+
rescue Exception
|
43
|
+
raise unless handle_exception($!)
|
44
|
+
end
|
35
45
|
end
|
46
|
+
ensure
|
47
|
+
mocha_teardown
|
36
48
|
end
|
49
|
+
result.add_run
|
50
|
+
yield(Test::Unit::TestCase::FINISHED, name)
|
37
51
|
ensure
|
38
|
-
|
52
|
+
@_result = nil
|
39
53
|
end
|
40
|
-
result.add_run
|
41
|
-
yield(Test::Unit::TestCase::FINISHED, name)
|
42
|
-
ensure
|
43
|
-
@_result = nil
|
44
54
|
end
|
45
55
|
end
|
46
56
|
end
|
47
|
-
|
48
57
|
end
|
49
|
-
|
50
58
|
end
|
51
|
-
|
52
59
|
end
|
@@ -1,52 +1,59 @@
|
|
1
|
-
require '
|
2
|
-
require 'mocha/integration/
|
1
|
+
require 'mocha/integration/assertion_counter'
|
2
|
+
require 'mocha/integration/monkey_patcher'
|
3
3
|
require 'mocha/expectation_error'
|
4
4
|
|
5
5
|
module Mocha
|
6
|
-
|
7
6
|
module Integration
|
8
|
-
|
9
7
|
module TestUnit
|
10
|
-
|
11
8
|
module GemVersion201To202
|
9
|
+
def self.applicable_to?(test_unit_version, ruby_version = nil)
|
10
|
+
Gem::Requirement.new('>= 2.0.1', '<= 2.0.2').satisfied_by?(test_unit_version)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.description
|
14
|
+
"monkey patch for Test::Unit gem >= v2.0.1 and <= v2.0.2"
|
15
|
+
end
|
16
|
+
|
12
17
|
def self.included(mod)
|
13
|
-
|
18
|
+
MonkeyPatcher.apply(mod, RunMethodPatch)
|
14
19
|
end
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
yield(Test::Unit::TestCase::STARTED, name)
|
20
|
+
|
21
|
+
module RunMethodPatch
|
22
|
+
def run(result)
|
23
|
+
assertion_counter = AssertionCounter.new(self)
|
20
24
|
begin
|
25
|
+
@_result = result
|
26
|
+
yield(Test::Unit::TestCase::STARTED, name)
|
21
27
|
begin
|
22
|
-
run_setup
|
23
|
-
run_test
|
24
|
-
mocha_verify(assertion_counter)
|
25
|
-
rescue Mocha::ExpectationError => e
|
26
|
-
add_failure(e.message, e.backtrace)
|
27
|
-
rescue Exception
|
28
|
-
@interrupted = true
|
29
|
-
raise unless handle_exception($!)
|
30
|
-
ensure
|
31
28
|
begin
|
32
|
-
|
29
|
+
run_setup
|
30
|
+
run_test
|
31
|
+
mocha_verify(assertion_counter)
|
32
|
+
rescue Mocha::ExpectationError => e
|
33
|
+
add_failure(e.message, e.backtrace)
|
33
34
|
rescue Exception
|
35
|
+
@interrupted = true
|
34
36
|
raise unless handle_exception($!)
|
37
|
+
ensure
|
38
|
+
begin
|
39
|
+
run_teardown
|
40
|
+
rescue Mocha::ExpectationError => e
|
41
|
+
add_failure(e.message, e.backtrace)
|
42
|
+
rescue Exception
|
43
|
+
raise unless handle_exception($!)
|
44
|
+
end
|
35
45
|
end
|
46
|
+
ensure
|
47
|
+
mocha_teardown
|
36
48
|
end
|
49
|
+
result.add_run
|
50
|
+
yield(Test::Unit::TestCase::FINISHED, name)
|
37
51
|
ensure
|
38
|
-
|
52
|
+
@_result = nil
|
39
53
|
end
|
40
|
-
result.add_run
|
41
|
-
yield(Test::Unit::TestCase::FINISHED, name)
|
42
|
-
ensure
|
43
|
-
@_result = nil
|
44
54
|
end
|
45
55
|
end
|
46
56
|
end
|
47
|
-
|
48
57
|
end
|
49
|
-
|
50
58
|
end
|
51
|
-
|
52
59
|
end
|
@@ -1,52 +1,59 @@
|
|
1
|
-
require '
|
2
|
-
require 'mocha/integration/
|
1
|
+
require 'mocha/integration/assertion_counter'
|
2
|
+
require 'mocha/integration/monkey_patcher'
|
3
3
|
require 'mocha/expectation_error'
|
4
4
|
|
5
5
|
module Mocha
|
6
|
-
|
7
6
|
module Integration
|
8
|
-
|
9
7
|
module TestUnit
|
10
|
-
|
11
8
|
module GemVersion203To220
|
9
|
+
def self.applicable_to?(test_unit_version, ruby_version = nil)
|
10
|
+
Gem::Requirement.new('>= 2.0.3', '<= 2.2.0').satisfied_by?(test_unit_version)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.description
|
14
|
+
"monkey patch for Test::Unit gem >= v2.0.3 and <= v2.2.0"
|
15
|
+
end
|
16
|
+
|
12
17
|
def self.included(mod)
|
13
|
-
|
18
|
+
MonkeyPatcher.apply(mod, RunMethodPatch)
|
14
19
|
end
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
yield(Test::Unit::TestCase::STARTED, name)
|
20
|
+
|
21
|
+
module RunMethodPatch
|
22
|
+
def run(result)
|
23
|
+
assertion_counter = AssertionCounter.new(self)
|
20
24
|
begin
|
25
|
+
@_result = result
|
26
|
+
yield(Test::Unit::TestCase::STARTED, name)
|
21
27
|
begin
|
22
|
-
run_setup
|
23
|
-
run_test
|
24
|
-
mocha_verify(assertion_counter)
|
25
|
-
rescue Mocha::ExpectationError => e
|
26
|
-
add_failure(e.message, e.backtrace)
|
27
|
-
rescue Exception
|
28
|
-
@interrupted = true
|
29
|
-
raise unless handle_exception($!)
|
30
|
-
ensure
|
31
28
|
begin
|
32
|
-
|
29
|
+
run_setup
|
30
|
+
run_test
|
31
|
+
mocha_verify(assertion_counter)
|
32
|
+
rescue Mocha::ExpectationError => e
|
33
|
+
add_failure(e.message, e.backtrace)
|
33
34
|
rescue Exception
|
35
|
+
@interrupted = true
|
34
36
|
raise unless handle_exception($!)
|
37
|
+
ensure
|
38
|
+
begin
|
39
|
+
run_teardown
|
40
|
+
rescue Mocha::ExpectationError => e
|
41
|
+
add_failure(e.message, e.backtrace)
|
42
|
+
rescue Exception
|
43
|
+
raise unless handle_exception($!)
|
44
|
+
end
|
35
45
|
end
|
46
|
+
ensure
|
47
|
+
mocha_teardown
|
36
48
|
end
|
49
|
+
result.add_run
|
50
|
+
yield(Test::Unit::TestCase::FINISHED, name)
|
37
51
|
ensure
|
38
|
-
|
52
|
+
# @_result = nil # For test-spec's after_all :<
|
39
53
|
end
|
40
|
-
result.add_run
|
41
|
-
yield(Test::Unit::TestCase::FINISHED, name)
|
42
|
-
ensure
|
43
|
-
# @_result = nil # For test-spec's after_all :<
|
44
54
|
end
|
45
55
|
end
|
46
56
|
end
|
47
|
-
|
48
57
|
end
|
49
|
-
|
50
58
|
end
|
51
|
-
|
52
59
|
end
|