mocha 1.1.0 → 1.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.github/FUNDING.yml +1 -0
- data/.rubocop.yml +61 -0
- data/.rubocop_todo.yml +27 -0
- data/.yardopts +1 -0
- data/CONTRIBUTING.md +4 -9
- data/README.md +114 -28
- data/RELEASE.md +248 -1
- data/Rakefile +53 -35
- data/gemfiles/Gemfile.test-unit.latest +5 -1
- data/init.rb +1 -3
- data/lib/mocha/any_instance_method.rb +12 -72
- data/lib/mocha/api.rb +121 -56
- data/lib/mocha/argument_iterator.rb +4 -8
- data/lib/mocha/backtrace_filter.rb +1 -5
- data/lib/mocha/block_matcher.rb +31 -0
- data/lib/mocha/cardinality.rb +60 -49
- data/lib/mocha/central.rb +21 -12
- data/lib/mocha/change_state_side_effect.rb +0 -4
- data/lib/mocha/class_methods.rb +19 -20
- data/lib/mocha/configuration.rb +361 -18
- data/lib/mocha/debug.rb +3 -2
- data/lib/mocha/deprecation.rb +8 -11
- data/lib/mocha/detection/mini_test.rb +0 -2
- data/lib/mocha/detection/test_unit.rb +3 -5
- data/lib/mocha/error_with_filtered_backtrace.rb +13 -0
- data/lib/mocha/exception_raiser.rb +4 -6
- data/lib/mocha/expectation.rb +125 -89
- data/lib/mocha/expectation_error.rb +1 -1
- data/lib/mocha/expectation_error_factory.rb +0 -1
- data/lib/mocha/expectation_list.rb +7 -11
- data/lib/mocha/hooks.rb +1 -3
- data/lib/mocha/in_state_ordering_constraint.rb +0 -4
- data/lib/mocha/inspect.rb +30 -38
- data/lib/mocha/instance_method.rb +15 -8
- data/lib/mocha/integration/mini_test/adapter.rb +2 -4
- data/lib/mocha/integration/mini_test/exception_translation.rb +1 -1
- data/lib/mocha/integration/mini_test/nothing.rb +4 -4
- data/lib/mocha/integration/mini_test/version_13.rb +4 -1
- data/lib/mocha/integration/mini_test/version_140.rb +4 -1
- data/lib/mocha/integration/mini_test/version_141.rb +4 -1
- data/lib/mocha/integration/mini_test/version_142_to_172.rb +4 -1
- data/lib/mocha/integration/mini_test/version_200.rb +4 -1
- data/lib/mocha/integration/mini_test/version_201_to_222.rb +4 -1
- data/lib/mocha/integration/mini_test/version_2110_to_2111.rb +4 -1
- data/lib/mocha/integration/mini_test/version_2112_to_320.rb +4 -1
- data/lib/mocha/integration/mini_test/version_230_to_2101.rb +4 -1
- data/lib/mocha/integration/mini_test.rb +7 -0
- data/lib/mocha/integration/monkey_patcher.rb +8 -2
- data/lib/mocha/integration/test_unit/adapter.rb +5 -6
- data/lib/mocha/integration/test_unit/gem_version_200.rb +5 -2
- data/lib/mocha/integration/test_unit/gem_version_201_to_202.rb +5 -2
- data/lib/mocha/integration/test_unit/gem_version_203_to_220.rb +5 -2
- data/lib/mocha/integration/test_unit/gem_version_230_to_250.rb +5 -2
- data/lib/mocha/integration/test_unit/nothing.rb +4 -4
- data/lib/mocha/integration/test_unit/ruby_version_185_and_below.rb +4 -1
- data/lib/mocha/integration/test_unit/ruby_version_186_and_above.rb +4 -1
- data/lib/mocha/integration/test_unit.rb +7 -0
- data/lib/mocha/integration.rb +2 -5
- data/lib/mocha/invocation.rb +77 -0
- data/lib/mocha/is_a.rb +0 -2
- data/lib/mocha/logger.rb +0 -4
- data/lib/mocha/macos_version.rb +5 -0
- data/lib/mocha/method_matcher.rb +1 -5
- data/lib/mocha/minitest.rb +8 -0
- data/lib/mocha/mock.rb +94 -46
- data/lib/mocha/mockery.rb +72 -98
- data/lib/mocha/names.rb +2 -12
- data/lib/mocha/not_initialized_error.rb +7 -0
- data/lib/mocha/object_methods.rb +25 -31
- data/lib/mocha/parameter_matchers/all_of.rb +2 -8
- data/lib/mocha/parameter_matchers/any_of.rb +2 -8
- data/lib/mocha/parameter_matchers/any_parameters.rb +3 -9
- data/lib/mocha/parameter_matchers/anything.rb +2 -8
- data/lib/mocha/parameter_matchers/base.rb +6 -12
- data/lib/mocha/parameter_matchers/equals.rb +1 -7
- data/lib/mocha/parameter_matchers/{query_string.rb → equivalent_uri.rb} +15 -15
- data/lib/mocha/parameter_matchers/has_entries.rb +2 -7
- data/lib/mocha/parameter_matchers/has_entry.rb +26 -21
- data/lib/mocha/parameter_matchers/has_key.rb +2 -7
- data/lib/mocha/parameter_matchers/has_keys.rb +53 -0
- data/lib/mocha/parameter_matchers/has_value.rb +2 -7
- data/lib/mocha/parameter_matchers/includes.rb +50 -8
- data/lib/mocha/parameter_matchers/instance_methods.rb +18 -0
- data/lib/mocha/parameter_matchers/instance_of.rb +0 -6
- data/lib/mocha/parameter_matchers/is_a.rb +2 -7
- data/lib/mocha/parameter_matchers/kind_of.rb +2 -6
- data/lib/mocha/parameter_matchers/not.rb +2 -7
- data/lib/mocha/parameter_matchers/optionally.rb +4 -10
- data/lib/mocha/parameter_matchers/regexp_matches.rb +0 -6
- data/lib/mocha/parameter_matchers/responds_with.rb +3 -8
- data/lib/mocha/parameter_matchers/yaml_equivalent.rb +2 -6
- data/lib/mocha/parameter_matchers.rb +3 -4
- data/lib/mocha/parameters_matcher.rb +6 -9
- data/lib/mocha/raised_exception.rb +11 -0
- data/lib/mocha/receivers.rb +10 -14
- data/lib/mocha/return_values.rb +4 -8
- data/lib/mocha/ruby_version.rb +4 -0
- data/lib/mocha/sequence.rb +4 -9
- data/lib/mocha/setup.rb +5 -0
- data/lib/mocha/single_return_value.rb +2 -5
- data/lib/mocha/singleton_class.rb +9 -0
- data/lib/mocha/state_machine.rb +33 -46
- data/lib/mocha/stubbed_method.rb +125 -0
- data/lib/mocha/stubbing_error.rb +2 -13
- data/lib/mocha/test_unit.rb +7 -2
- data/lib/mocha/thrower.rb +4 -6
- data/lib/mocha/thrown_object.rb +12 -0
- data/lib/mocha/version.rb +1 -1
- data/lib/mocha/yield_parameters.rb +7 -17
- data/lib/mocha.rb +8 -0
- data/mocha.gemspec +42 -40
- data/yard-templates/default/layout/html/google_analytics.erb +6 -9
- data/yard-templates/default/layout/html/setup.rb +2 -3
- metadata +45 -191
- data/bin/build-matrix +0 -71
- data/gemfiles/Gemfile.minitest.1.3.0 +0 -7
- data/gemfiles/Gemfile.minitest.1.4.0 +0 -7
- data/gemfiles/Gemfile.minitest.1.4.1 +0 -7
- data/gemfiles/Gemfile.minitest.1.4.2 +0 -7
- data/gemfiles/Gemfile.minitest.2.0.0 +0 -7
- data/gemfiles/Gemfile.minitest.2.0.1 +0 -7
- data/gemfiles/Gemfile.minitest.2.11.0 +0 -7
- data/gemfiles/Gemfile.minitest.2.11.2 +0 -7
- data/gemfiles/Gemfile.minitest.2.3.0 +0 -7
- data/gemfiles/Gemfile.test-unit.2.0.0 +0 -7
- data/gemfiles/Gemfile.test-unit.2.0.1 +0 -7
- data/gemfiles/Gemfile.test-unit.2.0.3 +0 -7
- data/lib/mocha/class_method.rb +0 -127
- data/lib/mocha/mini_test.rb +0 -3
- data/lib/mocha/module_method.rb +0 -16
- data/lib/mocha/module_methods.rb +0 -14
- data/lib/mocha/multiple_yields.rb +0 -20
- data/lib/mocha/no_yields.rb +0 -11
- data/lib/mocha/parameter_matchers/object.rb +0 -17
- data/lib/mocha/pretty_parameters.rb +0 -28
- data/lib/mocha/single_yield.rb +0 -18
- data/lib/mocha/standalone.rb +0 -4
- data/lib/mocha/unexpected_invocation.rb +0 -26
- data/lib/mocha_standalone.rb +0 -4
- data/test/acceptance/acceptance_test_helper.rb +0 -41
- data/test/acceptance/bug_18914_test.rb +0 -43
- data/test/acceptance/bug_21465_test.rb +0 -34
- data/test/acceptance/bug_21563_test.rb +0 -25
- data/test/acceptance/exception_rescue_test.rb +0 -55
- data/test/acceptance/expectations_on_multiple_methods_test.rb +0 -55
- data/test/acceptance/expected_invocation_count_test.rb +0 -232
- data/test/acceptance/failure_messages_test.rb +0 -64
- data/test/acceptance/issue_65_test.rb +0 -63
- data/test/acceptance/issue_70_test.rb +0 -55
- data/test/acceptance/mocha_example_test.rb +0 -98
- data/test/acceptance/mocha_test_result_test.rb +0 -84
- data/test/acceptance/mock_test.rb +0 -100
- data/test/acceptance/mock_with_initializer_block_test.rb +0 -51
- data/test/acceptance/mocked_methods_dispatch_test.rb +0 -78
- data/test/acceptance/multiple_expectations_failure_message_test.rb +0 -68
- data/test/acceptance/optional_parameters_test.rb +0 -70
- data/test/acceptance/parameter_matcher_test.rb +0 -337
- data/test/acceptance/partial_mocks_test.rb +0 -47
- data/test/acceptance/prepend_test.rb +0 -88
- data/test/acceptance/raise_exception_test.rb +0 -39
- data/test/acceptance/return_value_test.rb +0 -52
- data/test/acceptance/sequence_test.rb +0 -192
- data/test/acceptance/states_test.rb +0 -70
- data/test/acceptance/stub_any_instance_method_defined_on_superclass_test.rb +0 -34
- data/test/acceptance/stub_any_instance_method_test.rb +0 -238
- data/test/acceptance/stub_class_method_defined_on_active_record_association_proxy_test.rb +0 -106
- data/test/acceptance/stub_class_method_defined_on_class_test.rb +0 -78
- data/test/acceptance/stub_class_method_defined_on_module_test.rb +0 -75
- data/test/acceptance/stub_class_method_defined_on_superclass_test.rb +0 -112
- data/test/acceptance/stub_everything_test.rb +0 -56
- data/test/acceptance/stub_instance_method_defined_on_active_record_association_proxy_test.rb +0 -93
- data/test/acceptance/stub_instance_method_defined_on_class_and_aliased_test.rb +0 -69
- data/test/acceptance/stub_instance_method_defined_on_class_test.rb +0 -69
- data/test/acceptance/stub_instance_method_defined_on_kernel_module_test.rb +0 -75
- data/test/acceptance/stub_instance_method_defined_on_module_test.rb +0 -75
- data/test/acceptance/stub_instance_method_defined_on_object_class_test.rb +0 -75
- data/test/acceptance/stub_instance_method_defined_on_singleton_class_test.rb +0 -70
- data/test/acceptance/stub_instance_method_defined_on_superclass_test.rb +0 -72
- data/test/acceptance/stub_module_method_test.rb +0 -163
- data/test/acceptance/stub_test.rb +0 -52
- data/test/acceptance/stubba_example_test.rb +0 -102
- data/test/acceptance/stubba_test_result_test.rb +0 -66
- data/test/acceptance/stubbing_error_backtrace_test.rb +0 -64
- data/test/acceptance/stubbing_frozen_object_test.rb +0 -88
- data/test/acceptance/stubbing_method_accepting_block_parameter_test.rb +0 -48
- data/test/acceptance/stubbing_method_unnecessarily_test.rb +0 -65
- data/test/acceptance/stubbing_nil_test.rb +0 -59
- data/test/acceptance/stubbing_non_existent_any_instance_method_test.rb +0 -130
- data/test/acceptance/stubbing_non_existent_class_method_test.rb +0 -157
- data/test/acceptance/stubbing_non_existent_instance_method_test.rb +0 -147
- data/test/acceptance/stubbing_non_public_any_instance_method_test.rb +0 -130
- data/test/acceptance/stubbing_non_public_class_method_test.rb +0 -163
- data/test/acceptance/stubbing_non_public_instance_method_test.rb +0 -143
- data/test/acceptance/stubbing_on_non_mock_object_test.rb +0 -64
- data/test/acceptance/stubbing_same_class_method_on_parent_and_child_classes_test.rb +0 -35
- data/test/acceptance/throw_test.rb +0 -45
- data/test/acceptance/unexpected_invocation_test.rb +0 -25
- data/test/acceptance/unstubbing_test.rb +0 -168
- data/test/assertions.rb +0 -6
- data/test/deprecation_disabler.rb +0 -15
- data/test/execution_point.rb +0 -36
- data/test/integration/mini_test_test.rb +0 -8
- data/test/integration/shared_tests.rb +0 -174
- data/test/integration/test_unit_test.rb +0 -8
- data/test/method_definer.rb +0 -24
- data/test/mini_test_result.rb +0 -90
- data/test/minitest_result.rb +0 -49
- data/test/simple_counter.rb +0 -13
- data/test/test_helper.rb +0 -50
- data/test/test_runner.rb +0 -58
- data/test/test_unit_result.rb +0 -20
- data/test/unit/any_instance_method_test.rb +0 -132
- data/test/unit/array_inspect_test.rb +0 -16
- data/test/unit/backtrace_filter_test.rb +0 -19
- data/test/unit/cardinality_test.rb +0 -56
- data/test/unit/central_test.rb +0 -100
- data/test/unit/change_state_side_effect_test.rb +0 -41
- data/test/unit/class_method_test.rb +0 -223
- data/test/unit/class_methods_test.rb +0 -40
- data/test/unit/configuration_test.rb +0 -38
- data/test/unit/date_time_inspect_test.rb +0 -21
- data/test/unit/exception_raiser_test.rb +0 -42
- data/test/unit/expectation_list_test.rb +0 -82
- data/test/unit/expectation_test.rb +0 -497
- data/test/unit/hash_inspect_test.rb +0 -16
- data/test/unit/hooks_test.rb +0 -29
- data/test/unit/in_state_ordering_constraint_test.rb +0 -43
- data/test/unit/method_matcher_test.rb +0 -28
- data/test/unit/mock_test.rb +0 -341
- data/test/unit/mockery_test.rb +0 -151
- data/test/unit/module_methods_test.rb +0 -19
- data/test/unit/multiple_yields_test.rb +0 -18
- data/test/unit/no_yields_test.rb +0 -18
- data/test/unit/object_inspect_test.rb +0 -38
- data/test/unit/object_methods_test.rb +0 -46
- data/test/unit/parameter_matchers/all_of_test.rb +0 -26
- data/test/unit/parameter_matchers/any_of_test.rb +0 -26
- data/test/unit/parameter_matchers/anything_test.rb +0 -21
- data/test/unit/parameter_matchers/equals_test.rb +0 -25
- data/test/unit/parameter_matchers/has_entries_test.rb +0 -51
- data/test/unit/parameter_matchers/has_entry_test.rb +0 -129
- data/test/unit/parameter_matchers/has_key_test.rb +0 -55
- data/test/unit/parameter_matchers/has_value_test.rb +0 -57
- data/test/unit/parameter_matchers/includes_test.rb +0 -59
- data/test/unit/parameter_matchers/instance_of_test.rb +0 -25
- data/test/unit/parameter_matchers/is_a_test.rb +0 -25
- data/test/unit/parameter_matchers/kind_of_test.rb +0 -25
- data/test/unit/parameter_matchers/not_test.rb +0 -26
- data/test/unit/parameter_matchers/regexp_matches_test.rb +0 -46
- data/test/unit/parameter_matchers/responds_with_test.rb +0 -32
- data/test/unit/parameter_matchers/stub_matcher.rb +0 -27
- data/test/unit/parameter_matchers/yaml_equivalent_test.rb +0 -25
- data/test/unit/parameters_matcher_test.rb +0 -121
- data/test/unit/receivers_test.rb +0 -66
- data/test/unit/return_values_test.rb +0 -63
- data/test/unit/sequence_test.rb +0 -104
- data/test/unit/single_return_value_test.rb +0 -14
- data/test/unit/single_yield_test.rb +0 -18
- data/test/unit/state_machine_test.rb +0 -98
- data/test/unit/string_inspect_test.rb +0 -11
- data/test/unit/thrower_test.rb +0 -20
- data/test/unit/yield_parameters_test.rb +0 -93
@@ -1,168 +0,0 @@
|
|
1
|
-
require File.expand_path('../acceptance_test_helper', __FILE__)
|
2
|
-
require 'mocha/setup'
|
3
|
-
|
4
|
-
class UnstubbingTest < Mocha::TestCase
|
5
|
-
|
6
|
-
include AcceptanceTest
|
7
|
-
|
8
|
-
def setup
|
9
|
-
setup_acceptance_test
|
10
|
-
end
|
11
|
-
|
12
|
-
def teardown
|
13
|
-
teardown_acceptance_test
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_unstubbing_an_instance_method_should_restore_original_behaviour
|
17
|
-
klass = Class.new do
|
18
|
-
def my_instance_method; :original_return_value; end
|
19
|
-
end
|
20
|
-
test_result = run_as_test do
|
21
|
-
object = klass.new
|
22
|
-
object.stubs(:my_instance_method).returns(:new_return_value)
|
23
|
-
object.unstub(:my_instance_method)
|
24
|
-
assert_equal :original_return_value, object.my_instance_method
|
25
|
-
end
|
26
|
-
assert_passed(test_result)
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_unstubbing_a_class_method_should_restore_original_behaviour
|
30
|
-
klass = Class.new do
|
31
|
-
def self.my_class_method; :original_return_value; end
|
32
|
-
end
|
33
|
-
test_result = run_as_test do
|
34
|
-
klass.stubs(:my_class_method).returns(:new_return_value)
|
35
|
-
klass.unstub(:my_class_method)
|
36
|
-
assert_equal :original_return_value, klass.my_class_method
|
37
|
-
end
|
38
|
-
assert_passed(test_result)
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_unstubbing_a_module_method_should_restore_original_behaviour
|
42
|
-
mod = Module.new do
|
43
|
-
def self.my_module_method; :original_return_value; end
|
44
|
-
end
|
45
|
-
test_result = run_as_test do
|
46
|
-
mod.stubs(:my_module_method).returns(:new_return_value)
|
47
|
-
mod.unstub(:my_module_method)
|
48
|
-
assert_equal :original_return_value, mod.my_module_method
|
49
|
-
end
|
50
|
-
assert_passed(test_result)
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_unstubbing_a_module_method_defined_like_fileutils_in_ruby_2_0_should_restore_original_behaviour
|
54
|
-
mod = Module.new do
|
55
|
-
def my_module_method; :original_return_value; end
|
56
|
-
private :my_module_method
|
57
|
-
extend self
|
58
|
-
class << self
|
59
|
-
public :my_module_method
|
60
|
-
end
|
61
|
-
end
|
62
|
-
test_result = run_as_test do
|
63
|
-
mod.stubs(:my_module_method).returns(:new_return_value)
|
64
|
-
mod.unstub(:my_module_method)
|
65
|
-
assert_equal :original_return_value, mod.my_module_method
|
66
|
-
end
|
67
|
-
assert_passed(test_result)
|
68
|
-
end
|
69
|
-
|
70
|
-
def test_unstubbing_an_any_instance_method_should_restore_original_behaviour
|
71
|
-
klass = Class.new do
|
72
|
-
def my_instance_method; :original_return_value; end
|
73
|
-
end
|
74
|
-
test_result = run_as_test do
|
75
|
-
object = klass.new
|
76
|
-
klass.any_instance.stubs(:my_instance_method).returns(:new_return_value)
|
77
|
-
klass.any_instance.unstub(:my_instance_method)
|
78
|
-
assert_equal :original_return_value, object.my_instance_method
|
79
|
-
end
|
80
|
-
assert_passed(test_result)
|
81
|
-
end
|
82
|
-
|
83
|
-
def test_unstubbing_multiple_methods_should_restore_original_behaviour
|
84
|
-
klass = Class.new do
|
85
|
-
def my_first_instance_method; :original_return_value; end
|
86
|
-
def my_second_instance_method; :original_return_value; end
|
87
|
-
end
|
88
|
-
test_result = run_as_test do
|
89
|
-
object = klass.new
|
90
|
-
object.stubs(:my_first_instance_method).returns(:new_return_value)
|
91
|
-
object.stubs(:my_second_instance_method).returns(:new_return_value)
|
92
|
-
object.unstub(:my_first_instance_method, :my_second_instance_method)
|
93
|
-
assert_equal :original_return_value, object.my_first_instance_method
|
94
|
-
assert_equal :original_return_value, object.my_second_instance_method
|
95
|
-
end
|
96
|
-
assert_passed(test_result)
|
97
|
-
end
|
98
|
-
|
99
|
-
def test_unstubbing_a_method_multiple_times_should_restore_original_behaviour
|
100
|
-
klass = Class.new do
|
101
|
-
def my_instance_method; :original_return_value; end
|
102
|
-
end
|
103
|
-
test_result = run_as_test do
|
104
|
-
object = klass.new
|
105
|
-
object.stubs(:my_instance_method).returns(:new_return_value)
|
106
|
-
object.unstub(:my_instance_method)
|
107
|
-
object.unstub(:my_instance_method)
|
108
|
-
assert_equal :original_return_value, object.my_instance_method
|
109
|
-
end
|
110
|
-
assert_passed(test_result)
|
111
|
-
end
|
112
|
-
|
113
|
-
def test_unstubbing_a_non_stubbed_method_should_do_nothing
|
114
|
-
klass = Class.new do
|
115
|
-
def my_instance_method; :original_return_value; end
|
116
|
-
end
|
117
|
-
test_result = run_as_test do
|
118
|
-
object = klass.new
|
119
|
-
object.unstub(:my_instance_method)
|
120
|
-
assert_equal :original_return_value, object.my_instance_method
|
121
|
-
end
|
122
|
-
assert_passed(test_result)
|
123
|
-
end
|
124
|
-
|
125
|
-
def test_unstubbing_a_method_which_was_stubbed_multiple_times_should_restore_orginal_behaviour
|
126
|
-
klass = Class.new do
|
127
|
-
def my_instance_method; :original_return_value; end
|
128
|
-
end
|
129
|
-
test_result = run_as_test do
|
130
|
-
object = klass.new
|
131
|
-
object.stubs(:my_instance_method).with(:first).returns(:first_new_return_value)
|
132
|
-
object.stubs(:my_instance_method).with(:second).returns(:second_new_return_value)
|
133
|
-
object.unstub(:my_instance_method)
|
134
|
-
assert_equal :original_return_value, object.my_instance_method
|
135
|
-
end
|
136
|
-
assert_passed(test_result)
|
137
|
-
end
|
138
|
-
|
139
|
-
def test_unstubbing_a_method_should_not_unstub_other_stubbed_methods
|
140
|
-
klass = Class.new do
|
141
|
-
def my_first_instance_method; :first_return_value; end
|
142
|
-
def my_second_instance_method; :second_return_value; end
|
143
|
-
end
|
144
|
-
|
145
|
-
test_result = run_as_test do
|
146
|
-
object = klass.new
|
147
|
-
object.stubs(:my_first_instance_method).returns(:first_new_return_value)
|
148
|
-
object.stubs(:my_second_instance_method).returns(:second_new_return_value)
|
149
|
-
object.unstub(:my_first_instance_method)
|
150
|
-
assert_equal :first_return_value, object.my_first_instance_method
|
151
|
-
assert_equal :second_new_return_value, object.my_second_instance_method
|
152
|
-
end
|
153
|
-
assert_passed(test_result)
|
154
|
-
end
|
155
|
-
|
156
|
-
def test_unstubbing_a_method_should_remove_all_expectations_for_that_method
|
157
|
-
klass = Class.new do
|
158
|
-
def my_instance_method; :original_return_value; end
|
159
|
-
end
|
160
|
-
test_result = run_as_test do
|
161
|
-
object = klass.new
|
162
|
-
object.expects(:my_instance_method).with(:first)
|
163
|
-
object.expects(:my_instance_method).with(:second)
|
164
|
-
object.unstub(:my_instance_method)
|
165
|
-
end
|
166
|
-
assert_passed(test_result)
|
167
|
-
end
|
168
|
-
end
|
data/test/assertions.rb
DELETED
@@ -1,6 +0,0 @@
|
|
1
|
-
module Assertions
|
2
|
-
def assert_method_visiblity(object, method_name, visiblity)
|
3
|
-
method_key = RUBY_VERSION < '1.9' ? method_name.to_s : method_name.to_sym
|
4
|
-
assert object.send("#{visiblity}_methods", false).include?(method_key), "#{method_name} is not #{visiblity}"
|
5
|
-
end
|
6
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'mocha/deprecation'
|
2
|
-
|
3
|
-
module DeprecationDisabler
|
4
|
-
|
5
|
-
def disable_deprecations
|
6
|
-
original_mode = Mocha::Deprecation.mode
|
7
|
-
Mocha::Deprecation.mode = :disabled
|
8
|
-
begin
|
9
|
-
yield
|
10
|
-
ensure
|
11
|
-
Mocha::Deprecation.mode = original_mode
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
end
|
data/test/execution_point.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
class ExecutionPoint
|
2
|
-
|
3
|
-
attr_reader :backtrace
|
4
|
-
|
5
|
-
def self.current
|
6
|
-
new(caller)
|
7
|
-
end
|
8
|
-
|
9
|
-
def initialize(backtrace)
|
10
|
-
@backtrace = backtrace
|
11
|
-
end
|
12
|
-
|
13
|
-
def file_name
|
14
|
-
return "unknown" unless @backtrace && @backtrace.first
|
15
|
-
/\A(.*?):\d+/.match(@backtrace.first)[1]
|
16
|
-
end
|
17
|
-
|
18
|
-
def line_number
|
19
|
-
return "unknown" unless @backtrace && @backtrace.first
|
20
|
-
Integer(/\A.*?:(\d+)/.match(@backtrace.first)[1])
|
21
|
-
end
|
22
|
-
|
23
|
-
def ==(other)
|
24
|
-
return false unless other.is_a?(ExecutionPoint)
|
25
|
-
(file_name == other.file_name) and (line_number == other.line_number)
|
26
|
-
end
|
27
|
-
|
28
|
-
def to_s
|
29
|
-
"file: #{file_name}; line: #{line_number}"
|
30
|
-
end
|
31
|
-
|
32
|
-
def inspect
|
33
|
-
to_s
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|
@@ -1,174 +0,0 @@
|
|
1
|
-
require 'test_runner'
|
2
|
-
require 'execution_point'
|
3
|
-
|
4
|
-
module SharedTests
|
5
|
-
include TestRunner
|
6
|
-
|
7
|
-
def test_assertion_satisfied
|
8
|
-
test_result = run_as_test do
|
9
|
-
assert true
|
10
|
-
end
|
11
|
-
assert_passed(test_result)
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_assertion_unsatisfied
|
15
|
-
execution_point = nil
|
16
|
-
test_result = run_as_test do
|
17
|
-
execution_point = ExecutionPoint.current; flunk
|
18
|
-
end
|
19
|
-
assert_failed(test_result)
|
20
|
-
failure = test_result.failures.first
|
21
|
-
assert_equal execution_point, ExecutionPoint.new(failure.location)
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_mock_object_unexpected_invocation
|
25
|
-
execution_point = nil
|
26
|
-
test_result = run_as_test do
|
27
|
-
mock = mock("not expecting invocation")
|
28
|
-
execution_point = ExecutionPoint.current; mock.unexpected
|
29
|
-
end
|
30
|
-
assert_failed(test_result)
|
31
|
-
failure = test_result.failures.first
|
32
|
-
assert_equal execution_point, ExecutionPoint.new(failure.location)
|
33
|
-
assert_equal ["unexpected invocation: #<Mock:not expecting invocation>.unexpected()"], test_result.failure_message_lines
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_mock_object_explicitly_unexpected_invocation
|
37
|
-
execution_point = nil
|
38
|
-
test_result = run_as_test do
|
39
|
-
mock = mock("not expecting invocation")
|
40
|
-
mock.expects(:unexpected).never
|
41
|
-
execution_point = ExecutionPoint.current; mock.unexpected
|
42
|
-
end
|
43
|
-
assert_failed(test_result)
|
44
|
-
failure = test_result.failures.first
|
45
|
-
assert_equal execution_point, ExecutionPoint.new(failure.location)
|
46
|
-
assert_equal [
|
47
|
-
"unexpected invocation: #<Mock:not expecting invocation>.unexpected()",
|
48
|
-
"unsatisfied expectations:",
|
49
|
-
"- expected never, invoked once: #<Mock:not expecting invocation>.unexpected(any_parameters)"
|
50
|
-
], test_result.failure_message_lines
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_mock_object_unsatisfied_expectation
|
54
|
-
execution_point = nil
|
55
|
-
test_result = run_as_test do
|
56
|
-
mock = mock("expecting invocation")
|
57
|
-
execution_point = ExecutionPoint.current; mock.expects(:expected)
|
58
|
-
end
|
59
|
-
assert_failed(test_result)
|
60
|
-
failure = test_result.failures.first
|
61
|
-
assert_equal execution_point, ExecutionPoint.new(failure.location)
|
62
|
-
assert_equal [
|
63
|
-
"not all expectations were satisfied",
|
64
|
-
"unsatisfied expectations:",
|
65
|
-
"- expected exactly once, not yet invoked: #<Mock:expecting invocation>.expected(any_parameters)"
|
66
|
-
], test_result.failure_message_lines
|
67
|
-
end
|
68
|
-
|
69
|
-
def test_mock_object_unexpected_invocation_in_setup
|
70
|
-
execution_point = nil
|
71
|
-
test_result = run_as_tests(
|
72
|
-
:setup => lambda {
|
73
|
-
mock = mock("not expecting invocation")
|
74
|
-
execution_point = ExecutionPoint.current; mock.unexpected
|
75
|
-
},
|
76
|
-
:test_me => lambda {
|
77
|
-
assert true
|
78
|
-
}
|
79
|
-
)
|
80
|
-
assert_failed(test_result)
|
81
|
-
failure = test_result.failures.first
|
82
|
-
assert_equal execution_point, ExecutionPoint.new(failure.location)
|
83
|
-
assert_equal ["unexpected invocation: #<Mock:not expecting invocation>.unexpected()"], test_result.failure_message_lines
|
84
|
-
end
|
85
|
-
|
86
|
-
def test_mock_object_unsatisfied_expectation_in_setup
|
87
|
-
execution_point = nil
|
88
|
-
test_result = run_as_tests(
|
89
|
-
:setup => lambda {
|
90
|
-
mock = mock("expecting invocation")
|
91
|
-
execution_point = ExecutionPoint.current; mock.expects(:expected)
|
92
|
-
},
|
93
|
-
:test_me => lambda {
|
94
|
-
assert true
|
95
|
-
}
|
96
|
-
)
|
97
|
-
assert_failed(test_result)
|
98
|
-
failure = test_result.failures.first
|
99
|
-
assert_equal execution_point, ExecutionPoint.new(failure.location)
|
100
|
-
assert_equal [
|
101
|
-
"not all expectations were satisfied",
|
102
|
-
"unsatisfied expectations:",
|
103
|
-
"- expected exactly once, not yet invoked: #<Mock:expecting invocation>.expected(any_parameters)"
|
104
|
-
], test_result.failure_message_lines
|
105
|
-
end
|
106
|
-
|
107
|
-
def test_mock_object_unexpected_invocation_in_teardown
|
108
|
-
execution_point = nil
|
109
|
-
test_result = run_as_tests(
|
110
|
-
:test_me => lambda {
|
111
|
-
assert true
|
112
|
-
},
|
113
|
-
:teardown => lambda {
|
114
|
-
mock = mock("not expecting invocation")
|
115
|
-
execution_point = ExecutionPoint.current; mock.unexpected
|
116
|
-
}
|
117
|
-
)
|
118
|
-
assert_failed(test_result)
|
119
|
-
failure = test_result.failures.first
|
120
|
-
assert_equal execution_point, ExecutionPoint.new(failure.location)
|
121
|
-
assert_equal ["unexpected invocation: #<Mock:not expecting invocation>.unexpected()"], test_result.failure_message_lines
|
122
|
-
end
|
123
|
-
|
124
|
-
def test_real_object_explicitly_unexpected_invocation
|
125
|
-
execution_point = nil
|
126
|
-
object = Object.new
|
127
|
-
test_result = run_as_test do
|
128
|
-
object.expects(:unexpected).never
|
129
|
-
execution_point = ExecutionPoint.current; object.unexpected
|
130
|
-
end
|
131
|
-
assert_failed(test_result)
|
132
|
-
failure = test_result.failures.first
|
133
|
-
assert_equal execution_point, ExecutionPoint.new(failure.location)
|
134
|
-
assert_equal [
|
135
|
-
"unexpected invocation: #{object.mocha_inspect}.unexpected()",
|
136
|
-
"unsatisfied expectations:",
|
137
|
-
"- expected never, invoked once: #{object.mocha_inspect}.unexpected(any_parameters)"
|
138
|
-
], test_result.failure_message_lines
|
139
|
-
end
|
140
|
-
|
141
|
-
def test_real_object_unsatisfied_expectation
|
142
|
-
execution_point = nil
|
143
|
-
object = Object.new
|
144
|
-
test_result = run_as_test do
|
145
|
-
execution_point = ExecutionPoint.current; object.expects(:expected)
|
146
|
-
end
|
147
|
-
assert_failed(test_result)
|
148
|
-
failure = test_result.failures.first
|
149
|
-
assert_equal execution_point, ExecutionPoint.new(failure.location)
|
150
|
-
assert_equal [
|
151
|
-
"not all expectations were satisfied",
|
152
|
-
"unsatisfied expectations:",
|
153
|
-
"- expected exactly once, not yet invoked: #{object.mocha_inspect}.expected(any_parameters)"
|
154
|
-
], test_result.failure_message_lines
|
155
|
-
end
|
156
|
-
|
157
|
-
def test_real_object_expectation_does_not_leak_into_subsequent_test
|
158
|
-
execution_point = nil
|
159
|
-
klass = Class.new
|
160
|
-
test_result = run_as_tests(
|
161
|
-
:test_1 => lambda {
|
162
|
-
klass.expects(:foo)
|
163
|
-
klass.foo
|
164
|
-
},
|
165
|
-
:test_2 => lambda {
|
166
|
-
execution_point = ExecutionPoint.current; klass.foo
|
167
|
-
}
|
168
|
-
)
|
169
|
-
assert_failed(test_result)
|
170
|
-
exception = test_result.errors.first.exception
|
171
|
-
assert_equal execution_point, ExecutionPoint.new(exception.backtrace)
|
172
|
-
assert_match %r{undefined method `foo'}, exception.message
|
173
|
-
end
|
174
|
-
end
|
data/test/method_definer.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'metaclass'
|
2
|
-
|
3
|
-
module Mocha
|
4
|
-
|
5
|
-
module ObjectMethods
|
6
|
-
def define_instance_method(method_symbol, &block)
|
7
|
-
__metaclass__.send(:define_method, method_symbol, block)
|
8
|
-
end
|
9
|
-
|
10
|
-
def replace_instance_method(method_symbol, &block)
|
11
|
-
raise "Cannot replace #{method_symbol} as #{self} does not respond to it." unless self.respond_to?(method_symbol)
|
12
|
-
define_instance_method(method_symbol, &block)
|
13
|
-
end
|
14
|
-
|
15
|
-
def define_instance_accessor(*symbols)
|
16
|
-
symbols.each { |symbol| __metaclass__.send(:attr_accessor, symbol) }
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
|
-
class Object
|
23
|
-
include Mocha::ObjectMethods
|
24
|
-
end
|
data/test/mini_test_result.rb
DELETED
@@ -1,90 +0,0 @@
|
|
1
|
-
require 'stringio'
|
2
|
-
require 'minitest/unit'
|
3
|
-
|
4
|
-
class MiniTestResult
|
5
|
-
|
6
|
-
minitest_version = Gem::Version.new(::MiniTest::Unit::VERSION)
|
7
|
-
if Gem::Requirement.new('<= 4.6.1').satisfied_by?(minitest_version)
|
8
|
-
FAILURE_PATTERN = %r{(Failure)\:\n([^\(]+)\(([^\)]+)\) \[([^\]]+)\]\:\n(.*)\n}m
|
9
|
-
ERROR_PATTERN = %r{(Error)\:\n([^\(]+)\(([^\)]+)\)\:\n(.+?)\n}m
|
10
|
-
PATTERN_INDICES = { :method => 2, :testcase => 3 }
|
11
|
-
else
|
12
|
-
FAILURE_PATTERN = %r{(Failure)\:\n.([^#]+)\#([^ ]+) \[([^\]]+)\]\:\n(.*)\n}m
|
13
|
-
ERROR_PATTERN = %r{(Error)\:\n.([^#]+)\#([^ ]+)\:\n(.+?)\n}m
|
14
|
-
PATTERN_INDICES = { :method => 3, :testcase => 2 }
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.parse_failure(raw)
|
18
|
-
matches = FAILURE_PATTERN.match(raw)
|
19
|
-
return nil unless matches
|
20
|
-
Failure.new(matches[PATTERN_INDICES[:method]], matches[PATTERN_INDICES[:testcase]], [matches[4]], matches[5])
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.parse_error(raw)
|
24
|
-
matches = ERROR_PATTERN.match(raw)
|
25
|
-
return nil unless matches
|
26
|
-
backtrace = raw.gsub(ERROR_PATTERN, '').split("\n").map(&:strip)
|
27
|
-
Error.new(matches[PATTERN_INDICES[:method]], matches[PATTERN_INDICES[:testcase]], matches[4], backtrace)
|
28
|
-
end
|
29
|
-
|
30
|
-
class Failure
|
31
|
-
attr_reader :method, :test_case, :location, :message
|
32
|
-
def initialize(method, test_case, location, message)
|
33
|
-
@method, @test_case, @location, @message = method, test_case, location, message
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
class Error
|
38
|
-
class Exception
|
39
|
-
attr_reader :message, :backtrace
|
40
|
-
def initialize(message, location)
|
41
|
-
@message, @backtrace = message, location
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
attr_reader :method, :test_case, :exception
|
46
|
-
def initialize(method, test_case, message, backtrace)
|
47
|
-
@method, @test_case, @exception = method, test_case, Exception.new(message, backtrace)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def initialize(runner, tests)
|
52
|
-
@runner, @tests = runner, tests
|
53
|
-
end
|
54
|
-
|
55
|
-
def failure_count
|
56
|
-
@runner.failures
|
57
|
-
end
|
58
|
-
|
59
|
-
def assertion_count
|
60
|
-
@tests.inject(0) { |total, test| total + test._assertions }
|
61
|
-
end
|
62
|
-
|
63
|
-
def error_count
|
64
|
-
@runner.errors
|
65
|
-
end
|
66
|
-
|
67
|
-
def passed?
|
68
|
-
@tests.all?(&:passed?)
|
69
|
-
end
|
70
|
-
|
71
|
-
def failures
|
72
|
-
@runner.report.map { |puked| MiniTestResult.parse_failure(puked) }.compact
|
73
|
-
end
|
74
|
-
|
75
|
-
def errors
|
76
|
-
@runner.report.map { |puked| MiniTestResult.parse_error(puked) }.compact
|
77
|
-
end
|
78
|
-
|
79
|
-
def failure_messages
|
80
|
-
failures.map(&:message)
|
81
|
-
end
|
82
|
-
|
83
|
-
def failure_message_lines
|
84
|
-
failure_messages.map { |message| message.split("\n") }.flatten
|
85
|
-
end
|
86
|
-
|
87
|
-
def error_messages
|
88
|
-
errors.map { |e| e.exception.message }
|
89
|
-
end
|
90
|
-
end
|
data/test/minitest_result.rb
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
require 'forwardable'
|
2
|
-
|
3
|
-
class MinitestResult
|
4
|
-
|
5
|
-
class Failure
|
6
|
-
extend Forwardable
|
7
|
-
def_delegators :@failure, :message, :backtrace
|
8
|
-
|
9
|
-
def initialize(failure)
|
10
|
-
@failure = failure
|
11
|
-
end
|
12
|
-
|
13
|
-
def location
|
14
|
-
Minitest.filter_backtrace(backtrace)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def initialize(tests)
|
19
|
-
@tests = tests
|
20
|
-
end
|
21
|
-
|
22
|
-
def failures
|
23
|
-
@tests.map(&:failures).flatten.select { |r| Minitest::Assertion === r }.map { |f| Failure.new(f) }
|
24
|
-
end
|
25
|
-
|
26
|
-
def failure_count
|
27
|
-
failures.length
|
28
|
-
end
|
29
|
-
|
30
|
-
def failure_message_lines
|
31
|
-
failures.map { |f| f.message.split("\n") }.flatten
|
32
|
-
end
|
33
|
-
|
34
|
-
def errors
|
35
|
-
@tests.map(&:failures).flatten.select { |r| Minitest::UnexpectedError === r }
|
36
|
-
end
|
37
|
-
|
38
|
-
def error_count
|
39
|
-
errors.length
|
40
|
-
end
|
41
|
-
|
42
|
-
def error_messages
|
43
|
-
errors.map { |e| e.message.split("\n") }.flatten
|
44
|
-
end
|
45
|
-
|
46
|
-
def assertion_count
|
47
|
-
@tests.inject(0) { |total, test| total + test.assertions }
|
48
|
-
end
|
49
|
-
end
|
data/test/simple_counter.rb
DELETED
data/test/test_helper.rb
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
unless defined?(STANDARD_OBJECT_PUBLIC_INSTANCE_METHODS)
|
2
|
-
STANDARD_OBJECT_PUBLIC_INSTANCE_METHODS = Object.instance_methods + Object.private_instance_methods
|
3
|
-
end
|
4
|
-
|
5
|
-
$:.unshift File.expand_path(File.join(File.dirname(__FILE__), "..", "lib"))
|
6
|
-
$:.unshift File.expand_path(File.join(File.dirname(__FILE__)))
|
7
|
-
$:.unshift File.expand_path(File.join(File.dirname(__FILE__), 'unit'))
|
8
|
-
$:.unshift File.expand_path(File.join(File.dirname(__FILE__), 'unit', 'parameter_matchers'))
|
9
|
-
$:.unshift File.expand_path(File.join(File.dirname(__FILE__), 'acceptance'))
|
10
|
-
|
11
|
-
require 'mocha/detection/mini_test'
|
12
|
-
|
13
|
-
begin
|
14
|
-
require 'minitest'
|
15
|
-
rescue LoadError
|
16
|
-
end
|
17
|
-
begin
|
18
|
-
require 'minitest/unit'
|
19
|
-
rescue LoadError
|
20
|
-
end
|
21
|
-
|
22
|
-
module Mocha; end
|
23
|
-
|
24
|
-
if (minitest_testcase = Mocha::Detection::MiniTest.testcase) && (ENV['MOCHA_RUN_INTEGRATION_TESTS'] != 'test-unit')
|
25
|
-
begin
|
26
|
-
require 'minitest/autorun'
|
27
|
-
rescue LoadError
|
28
|
-
MiniTest::Unit.autorun
|
29
|
-
end
|
30
|
-
class Mocha::TestCase < minitest_testcase
|
31
|
-
def assert_nothing_raised(exception = StandardError)
|
32
|
-
yield
|
33
|
-
rescue exception => e
|
34
|
-
flunk "Unexpected exception raised: #{e}"
|
35
|
-
end
|
36
|
-
|
37
|
-
alias_method :assert_not_nil, :refute_nil
|
38
|
-
alias_method :assert_raise, :assert_raises
|
39
|
-
alias_method :assert_not_same, :refute_same
|
40
|
-
alias_method :assert_no_match, :refute_match
|
41
|
-
end
|
42
|
-
else
|
43
|
-
require 'test/unit'
|
44
|
-
class Mocha::TestCase < Test::Unit::TestCase
|
45
|
-
def test_dummy
|
46
|
-
# Some versions (?) of Test::Unit try to run this base class as a test case
|
47
|
-
# and it fails because it has no test methods, so I'm adding a dummy test.
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|