mocha 1.2.1 → 1.16.1
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/Gemfile +29 -0
- data/README.md +104 -106
- data/RELEASE.md +277 -1
- data/Rakefile +46 -44
- data/gemfiles/Gemfile.minitest.latest +1 -0
- data/gemfiles/Gemfile.test-unit.latest +2 -5
- data/init.rb +1 -3
- data/lib/mocha/any_instance_method.rb +9 -62
- data/lib/mocha/api.rb +144 -68
- 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 -21
- data/lib/mocha/configuration.rb +372 -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 +11 -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 +5 -7
- 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_186_and_above.rb +4 -1
- data/lib/mocha/integration/test_unit.rb +7 -2
- data/lib/mocha/integration.rb +2 -5
- data/lib/mocha/invocation.rb +86 -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 +9 -0
- data/lib/mocha/mock.rb +102 -58
- data/lib/mocha/mockery.rb +70 -99
- 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 +0 -6
- 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 +6 -7
- 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 +8 -1
- 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/state_machine.rb +33 -46
- data/lib/mocha/stubbed_method.rb +124 -0
- data/lib/mocha/stubbing_error.rb +2 -13
- data/lib/mocha/test_unit.rb +8 -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/mocha.gemspec +14 -65
- data/yard-templates/default/layout/html/google_analytics.erb +6 -9
- data/yard-templates/default/layout/html/setup.rb +2 -3
- metadata +25 -247
- data/bin/build-matrix +0 -70
- 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 -119
- data/lib/mocha/integration/test_unit/ruby_version_185_and_below.rb +0 -58
- 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_272_test.rb +0 -52
- 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 -89
- 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 -280
- 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 -78
- 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_method_defined_on_module_and_aliased_test.rb +0 -39
- 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 -61
- data/test/acceptance/stubbing_non_existent_any_instance_method_test.rb +0 -143
- 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 -8
- 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 -134
- 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 -225
- 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 -342
- 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 -39
- 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 -102
- 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,232 +0,0 @@
|
|
1
|
-
require File.expand_path('../acceptance_test_helper', __FILE__)
|
2
|
-
require 'mocha/setup'
|
3
|
-
|
4
|
-
class ExpectedInvocationCountTest < 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_should_pass_if_method_is_never_expected_and_is_never_called
|
17
|
-
test_result = run_as_test do
|
18
|
-
mock = mock('mock')
|
19
|
-
mock.expects(:method).never
|
20
|
-
0.times { mock.method }
|
21
|
-
end
|
22
|
-
assert_passed(test_result)
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_should_fail_fast_if_method_is_never_expected_but_is_called_once
|
26
|
-
test_result = run_as_test do
|
27
|
-
mock = mock('mock')
|
28
|
-
mock.expects(:method).never
|
29
|
-
1.times { mock.method }
|
30
|
-
end
|
31
|
-
assert_failed(test_result)
|
32
|
-
assert_equal [
|
33
|
-
"unexpected invocation: #<Mock:mock>.method()",
|
34
|
-
"unsatisfied expectations:",
|
35
|
-
"- expected never, invoked once: #<Mock:mock>.method(any_parameters)"
|
36
|
-
], test_result.failure_message_lines
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_should_pass_if_method_is_expected_twice_and_is_called_twice
|
40
|
-
test_result = run_as_test do
|
41
|
-
mock = mock('mock')
|
42
|
-
mock.expects(:method).twice
|
43
|
-
2.times { mock.method }
|
44
|
-
end
|
45
|
-
assert_passed(test_result)
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_should_fail_if_method_is_expected_twice_but_is_called_once
|
49
|
-
test_result = run_as_test do
|
50
|
-
mock = mock('mock')
|
51
|
-
mock.expects(:method).twice
|
52
|
-
1.times { mock.method }
|
53
|
-
end
|
54
|
-
assert_failed(test_result)
|
55
|
-
assert_equal [
|
56
|
-
"not all expectations were satisfied",
|
57
|
-
"unsatisfied expectations:",
|
58
|
-
"- expected exactly twice, invoked once: #<Mock:mock>.method(any_parameters)"
|
59
|
-
], test_result.failure_message_lines
|
60
|
-
end
|
61
|
-
|
62
|
-
def test_should_fail_fast_if_method_is_expected_twice_but_is_called_three_times
|
63
|
-
test_result = run_as_test do
|
64
|
-
mock = mock('mock')
|
65
|
-
mock.expects(:method).twice
|
66
|
-
3.times { mock.method }
|
67
|
-
end
|
68
|
-
assert_failed(test_result)
|
69
|
-
assert_equal [
|
70
|
-
"unexpected invocation: #<Mock:mock>.method()",
|
71
|
-
"unsatisfied expectations:",
|
72
|
-
"- expected exactly twice, invoked 3 times: #<Mock:mock>.method(any_parameters)"
|
73
|
-
], test_result.failure_message_lines
|
74
|
-
end
|
75
|
-
|
76
|
-
def test_should_pass_if_method_is_expected_between_two_and_four_times_and_is_called_twice
|
77
|
-
test_result = run_as_test do
|
78
|
-
mock = mock('mock')
|
79
|
-
mock.expects(:method).times(2..4)
|
80
|
-
2.times { mock.method }
|
81
|
-
end
|
82
|
-
assert_passed(test_result)
|
83
|
-
end
|
84
|
-
|
85
|
-
def test_should_pass_if_method_is_expected_between_two_and_four_times_and_is_called_three_times
|
86
|
-
test_result = run_as_test do
|
87
|
-
mock = mock('mock')
|
88
|
-
mock.expects(:method).times(2..4)
|
89
|
-
3.times { mock.method }
|
90
|
-
end
|
91
|
-
assert_passed(test_result)
|
92
|
-
end
|
93
|
-
|
94
|
-
def test_should_pass_if_method_is_expected_between_two_and_four_times_and_is_called_four_times
|
95
|
-
test_result = run_as_test do
|
96
|
-
mock = mock('mock')
|
97
|
-
mock.expects(:method).times(2..4)
|
98
|
-
4.times { mock.method }
|
99
|
-
end
|
100
|
-
assert_passed(test_result)
|
101
|
-
end
|
102
|
-
|
103
|
-
def test_should_fail_if_method_is_expected_between_two_and_four_times_and_is_called_once
|
104
|
-
test_result = run_as_test do
|
105
|
-
mock = mock('mock')
|
106
|
-
mock.expects(:method).times(2..4)
|
107
|
-
1.times { mock.method }
|
108
|
-
end
|
109
|
-
assert_failed(test_result)
|
110
|
-
assert_equal [
|
111
|
-
"not all expectations were satisfied",
|
112
|
-
"unsatisfied expectations:",
|
113
|
-
"- expected between 2 and 4 times, invoked once: #<Mock:mock>.method(any_parameters)"
|
114
|
-
], test_result.failure_message_lines
|
115
|
-
end
|
116
|
-
|
117
|
-
def test_should_fail_fast_if_method_is_expected_between_two_and_four_times_and_is_called_five_times
|
118
|
-
test_result = run_as_test do
|
119
|
-
mock = mock('mock')
|
120
|
-
mock.expects(:method).times(2..4)
|
121
|
-
5.times { mock.method }
|
122
|
-
end
|
123
|
-
assert_failed(test_result)
|
124
|
-
assert_equal [
|
125
|
-
"unexpected invocation: #<Mock:mock>.method()",
|
126
|
-
"unsatisfied expectations:",
|
127
|
-
"- expected between 2 and 4 times, invoked 5 times: #<Mock:mock>.method(any_parameters)"
|
128
|
-
], test_result.failure_message_lines
|
129
|
-
end
|
130
|
-
|
131
|
-
def test_should_pass_if_method_is_expected_at_least_once_and_is_called_once
|
132
|
-
test_result = run_as_test do
|
133
|
-
mock = mock('mock')
|
134
|
-
mock.expects(:method).at_least_once
|
135
|
-
1.times { mock.method }
|
136
|
-
end
|
137
|
-
assert_passed(test_result)
|
138
|
-
end
|
139
|
-
|
140
|
-
def test_should_pass_if_method_is_expected_at_least_once_and_is_called_twice
|
141
|
-
test_result = run_as_test do
|
142
|
-
mock = mock('mock')
|
143
|
-
mock.expects(:method).at_least_once
|
144
|
-
2.times { mock.method }
|
145
|
-
end
|
146
|
-
assert_passed(test_result)
|
147
|
-
end
|
148
|
-
|
149
|
-
def test_should_fail_if_method_is_expected_at_least_once_but_is_never_called
|
150
|
-
test_result = run_as_test do
|
151
|
-
mock = mock('mock')
|
152
|
-
mock.expects(:method).at_least_once
|
153
|
-
0.times { mock.method }
|
154
|
-
end
|
155
|
-
assert_failed(test_result)
|
156
|
-
assert_equal [
|
157
|
-
"not all expectations were satisfied",
|
158
|
-
"unsatisfied expectations:",
|
159
|
-
"- expected at least once, not yet invoked: #<Mock:mock>.method(any_parameters)"
|
160
|
-
], test_result.failure_message_lines
|
161
|
-
end
|
162
|
-
|
163
|
-
def test_should_pass_if_method_is_expected_at_most_once_and_is_never_called
|
164
|
-
test_result = run_as_test do
|
165
|
-
mock = mock('mock')
|
166
|
-
mock.expects(:method).at_most_once
|
167
|
-
0.times { mock.method }
|
168
|
-
end
|
169
|
-
assert_passed(test_result)
|
170
|
-
end
|
171
|
-
|
172
|
-
def test_should_pass_if_method_is_expected_at_most_once_and_called_once
|
173
|
-
test_result = run_as_test do
|
174
|
-
mock = mock('mock')
|
175
|
-
mock.expects(:method).at_most_once
|
176
|
-
1.times { mock.method }
|
177
|
-
end
|
178
|
-
assert_passed(test_result)
|
179
|
-
end
|
180
|
-
|
181
|
-
def test_should_fail_fast_if_method_is_expected_at_most_once_but_is_called_twice
|
182
|
-
test_result = run_as_test do
|
183
|
-
mock = mock('mock')
|
184
|
-
mock.expects(:method).at_most_once
|
185
|
-
2.times { mock.method }
|
186
|
-
end
|
187
|
-
assert_failed(test_result)
|
188
|
-
assert_equal [
|
189
|
-
"unexpected invocation: #<Mock:mock>.method()",
|
190
|
-
"unsatisfied expectations:",
|
191
|
-
"- expected at most once, invoked twice: #<Mock:mock>.method(any_parameters)"
|
192
|
-
], test_result.failure_message_lines
|
193
|
-
end
|
194
|
-
|
195
|
-
def test_should_pass_if_method_is_never_expected_and_is_never_called_even_if_everything_is_stubbed
|
196
|
-
test_result = run_as_test do
|
197
|
-
stub = stub_everything('stub')
|
198
|
-
stub.expects(:method).never
|
199
|
-
0.times { stub.method }
|
200
|
-
end
|
201
|
-
assert_passed(test_result)
|
202
|
-
end
|
203
|
-
|
204
|
-
def test_should_fail_fast_if_method_is_never_expected_but_is_called_once_even_if_everything_is_stubbed
|
205
|
-
test_result = run_as_test do
|
206
|
-
stub = stub_everything('stub')
|
207
|
-
stub.expects(:method).never
|
208
|
-
1.times { stub.method }
|
209
|
-
end
|
210
|
-
assert_failed(test_result)
|
211
|
-
assert_equal [
|
212
|
-
"unexpected invocation: #<Mock:stub>.method()",
|
213
|
-
"unsatisfied expectations:",
|
214
|
-
"- expected never, invoked once: #<Mock:stub>.method(any_parameters)"
|
215
|
-
], test_result.failure_message_lines
|
216
|
-
end
|
217
|
-
|
218
|
-
def test_should_fail_fast_if_there_is_no_matching_expectation
|
219
|
-
test_result = run_as_test do
|
220
|
-
mock = mock('mock')
|
221
|
-
mock.expects(:method).with(1)
|
222
|
-
1.times { mock.method }
|
223
|
-
end
|
224
|
-
assert_failed(test_result)
|
225
|
-
assert_equal [
|
226
|
-
"unexpected invocation: #<Mock:mock>.method()",
|
227
|
-
"unsatisfied expectations:",
|
228
|
-
"- expected exactly once, not yet invoked: #<Mock:mock>.method(1)"
|
229
|
-
], test_result.failure_message_lines
|
230
|
-
end
|
231
|
-
|
232
|
-
end
|
@@ -1,64 +0,0 @@
|
|
1
|
-
require File.expand_path('../acceptance_test_helper', __FILE__)
|
2
|
-
require 'mocha/setup'
|
3
|
-
|
4
|
-
class FailureMessagesTest < Mocha::TestCase
|
5
|
-
|
6
|
-
OBJECT_ADDRESS_PATTERN = '0x[0-9A-Fa-f]{1,12}'
|
7
|
-
|
8
|
-
include AcceptanceTest
|
9
|
-
|
10
|
-
def setup
|
11
|
-
setup_acceptance_test
|
12
|
-
end
|
13
|
-
|
14
|
-
def teardown
|
15
|
-
teardown_acceptance_test
|
16
|
-
end
|
17
|
-
|
18
|
-
class Foo; end
|
19
|
-
|
20
|
-
def test_should_display_class_name_when_expectation_was_on_class
|
21
|
-
test_result = run_as_test do
|
22
|
-
Foo.expects(:bar)
|
23
|
-
end
|
24
|
-
assert_match Regexp.new('FailureMessagesTest::Foo'), test_result.failures[0].message
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_should_display_class_name_and_address_when_expectation_was_on_instance
|
28
|
-
test_result = run_as_test do
|
29
|
-
Foo.new.expects(:bar)
|
30
|
-
end
|
31
|
-
assert_match Regexp.new("#<FailureMessagesTest::Foo:#{OBJECT_ADDRESS_PATTERN}>"), test_result.failures[0].message
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_should_display_class_name_and_any_instance_prefix_when_expectation_was_on_any_instance
|
35
|
-
test_result = run_as_test do
|
36
|
-
Foo.any_instance.expects(:bar)
|
37
|
-
end
|
38
|
-
assert_match Regexp.new('#<AnyInstance:FailureMessagesTest::Foo>'), test_result.failures[0].message
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_should_display_mock_name_when_expectation_was_on_named_mock
|
42
|
-
test_result = run_as_test do
|
43
|
-
foo = mock('foo')
|
44
|
-
foo.expects(:bar)
|
45
|
-
end
|
46
|
-
assert_match Regexp.new('#<Mock:foo>'), test_result.failures[0].message
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_should_display_mock_address_when_expectation_was_on_unnamed_mock
|
50
|
-
test_result = run_as_test do
|
51
|
-
foo = mock()
|
52
|
-
foo.expects(:bar)
|
53
|
-
end
|
54
|
-
assert_match Regexp.new("#<Mock:#{OBJECT_ADDRESS_PATTERN}>"), test_result.failures[0].message
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_should_display_string_when_expectation_was_on_string
|
58
|
-
test_result = run_as_test do
|
59
|
-
'Foo'.expects(:bar)
|
60
|
-
end
|
61
|
-
assert_match Regexp.new("'Foo'"), test_result.failures[0].message
|
62
|
-
end
|
63
|
-
|
64
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
require File.expand_path('../acceptance_test_helper', __FILE__)
|
2
|
-
require 'mocha/setup'
|
3
|
-
|
4
|
-
class Issue272Test < 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
|
-
module Mod
|
17
|
-
private
|
18
|
-
|
19
|
-
def foo
|
20
|
-
'original-foo'
|
21
|
-
end
|
22
|
-
|
23
|
-
def bar
|
24
|
-
'original-bar'
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
class Klass
|
29
|
-
extend Mod
|
30
|
-
|
31
|
-
class << self
|
32
|
-
public :foo
|
33
|
-
public :bar
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_private_methods_in_module_used_to_extend_class_and_made_public
|
38
|
-
test_result = run_as_test do
|
39
|
-
Klass.stubs(:foo).returns('stubbed-foo')
|
40
|
-
# hangs in next line executing:
|
41
|
-
# `@original_method = stubbee._method(method)`
|
42
|
-
# in Mocha::ClassMethod#hide_original_method
|
43
|
-
# but only in Ruby v2.3, not v2.2
|
44
|
-
Klass.stubs(:bar).returns('stubbed-bar')
|
45
|
-
assert_equal 'stubbed-foo', Klass.foo
|
46
|
-
assert_equal 'stubbed-bar', Klass.bar
|
47
|
-
end
|
48
|
-
assert_passed(test_result)
|
49
|
-
assert_equal 'original-foo', Klass.foo
|
50
|
-
assert_equal 'original-bar', Klass.bar
|
51
|
-
end
|
52
|
-
end
|
@@ -1,63 +0,0 @@
|
|
1
|
-
require File.expand_path('../acceptance_test_helper', __FILE__)
|
2
|
-
require 'mocha/setup'
|
3
|
-
|
4
|
-
class Issue65Test < 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_expectations_on_class_methods_on_same_class_should_be_verified_in_consecutive_tests
|
17
|
-
klass = Class.new do
|
18
|
-
def self.foo; end
|
19
|
-
def self.bar; end
|
20
|
-
end
|
21
|
-
test_1 = run_as_test do
|
22
|
-
klass.expects(:foo)
|
23
|
-
klass.foo
|
24
|
-
end
|
25
|
-
assert_passed(test_1)
|
26
|
-
test_2 = run_as_test do
|
27
|
-
klass.expects(:bar)
|
28
|
-
end
|
29
|
-
assert_failed(test_2)
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_expectations_on_any_instance_methods_on_same_class_should_be_verified_in_consecutive_tests
|
33
|
-
klass = Class.new do
|
34
|
-
def foo; end
|
35
|
-
def bar; end
|
36
|
-
end
|
37
|
-
test_1 = run_as_test do
|
38
|
-
klass.any_instance.expects(:foo)
|
39
|
-
klass.new.foo
|
40
|
-
end
|
41
|
-
assert_passed(test_1)
|
42
|
-
test_2 = run_as_test do
|
43
|
-
klass.any_instance.expects(:bar)
|
44
|
-
end
|
45
|
-
assert_failed(test_2)
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_expectations_on_instance_methods_on_same_object_should_be_verified_in_consecutive_tests
|
49
|
-
instance = Class.new do
|
50
|
-
def foo; end
|
51
|
-
def bar; end
|
52
|
-
end.new
|
53
|
-
test_1 = run_as_test do
|
54
|
-
instance.expects(:foo)
|
55
|
-
instance.foo
|
56
|
-
end
|
57
|
-
assert_passed(test_1)
|
58
|
-
test_2 = run_as_test do
|
59
|
-
instance.expects(:bar)
|
60
|
-
end
|
61
|
-
assert_failed(test_2)
|
62
|
-
end
|
63
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
require File.expand_path('../acceptance_test_helper', __FILE__)
|
2
|
-
require 'mocha/setup'
|
3
|
-
|
4
|
-
class Issue70Test < 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_should_stub_expectations_instance_method
|
17
|
-
instance = Class.new do
|
18
|
-
def expectations
|
19
|
-
:original_return_value
|
20
|
-
end
|
21
|
-
end.new
|
22
|
-
test_result = run_as_test do
|
23
|
-
instance.stubs(:expectations).returns(:stubbed_return_value)
|
24
|
-
assert_equal :stubbed_return_value, instance.expectations
|
25
|
-
end
|
26
|
-
assert_passed(test_result)
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_should_stub_expectations_class_method
|
30
|
-
klass = Class.new do
|
31
|
-
def self.expectations
|
32
|
-
:original_return_value
|
33
|
-
end
|
34
|
-
end
|
35
|
-
test_result = run_as_test do
|
36
|
-
klass.stubs(:expectations).returns(:stubbed_return_value)
|
37
|
-
assert_equal :stubbed_return_value, klass.expectations
|
38
|
-
end
|
39
|
-
assert_passed(test_result)
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_should_stub_expectations_any_instance_method
|
43
|
-
klass = Class.new do
|
44
|
-
def expectations
|
45
|
-
:original_return_value
|
46
|
-
end
|
47
|
-
end
|
48
|
-
instance = klass.new
|
49
|
-
test_result = run_as_test do
|
50
|
-
klass.any_instance.stubs(:expectations).returns(:stubbed_return_value)
|
51
|
-
assert_equal :stubbed_return_value, instance.expectations
|
52
|
-
end
|
53
|
-
assert_passed(test_result)
|
54
|
-
end
|
55
|
-
end
|
@@ -1,98 +0,0 @@
|
|
1
|
-
require File.expand_path('../../test_helper', __FILE__)
|
2
|
-
require 'mocha/setup'
|
3
|
-
|
4
|
-
class MochaExampleTest < Mocha::TestCase
|
5
|
-
|
6
|
-
class Rover
|
7
|
-
|
8
|
-
def initialize(left_track, right_track, steps_per_metre, steps_per_degree)
|
9
|
-
@left_track, @right_track, @steps_per_metre, @steps_per_degree = left_track, right_track, steps_per_metre, steps_per_degree
|
10
|
-
end
|
11
|
-
|
12
|
-
def forward(metres)
|
13
|
-
@left_track.step(metres * @steps_per_metre)
|
14
|
-
@right_track.step(metres * @steps_per_metre)
|
15
|
-
wait
|
16
|
-
end
|
17
|
-
|
18
|
-
def backward(metres)
|
19
|
-
forward(-metres)
|
20
|
-
end
|
21
|
-
|
22
|
-
def left(degrees)
|
23
|
-
@left_track.step(-degrees * @steps_per_degree)
|
24
|
-
@right_track.step(+degrees * @steps_per_degree)
|
25
|
-
wait
|
26
|
-
end
|
27
|
-
|
28
|
-
def right(degrees)
|
29
|
-
left(-degrees)
|
30
|
-
end
|
31
|
-
|
32
|
-
def wait
|
33
|
-
while (@left_track.moving? or @right_track.moving?); end
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_should_step_both_tracks_forward_ten_steps
|
39
|
-
left_track = mock('left_track')
|
40
|
-
right_track = mock('right_track')
|
41
|
-
steps_per_metre = 5
|
42
|
-
rover = Rover.new(left_track, right_track, steps_per_metre, nil)
|
43
|
-
|
44
|
-
left_track.expects(:step).with(10)
|
45
|
-
right_track.expects(:step).with(10)
|
46
|
-
|
47
|
-
left_track.stubs(:moving?).returns(false)
|
48
|
-
right_track.stubs(:moving?).returns(false)
|
49
|
-
|
50
|
-
rover.forward(2)
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_should_step_both_tracks_backward_ten_steps
|
54
|
-
left_track = mock('left_track')
|
55
|
-
right_track = mock('right_track')
|
56
|
-
steps_per_metre = 5
|
57
|
-
rover = Rover.new(left_track, right_track, steps_per_metre, nil)
|
58
|
-
|
59
|
-
left_track.expects(:step).with(-10)
|
60
|
-
right_track.expects(:step).with(-10)
|
61
|
-
|
62
|
-
left_track.stubs(:moving?).returns(false)
|
63
|
-
right_track.stubs(:moving?).returns(false)
|
64
|
-
|
65
|
-
rover.backward(2)
|
66
|
-
end
|
67
|
-
|
68
|
-
def test_should_step_left_track_forwards_five_steps_and_right_track_backwards_five_steps
|
69
|
-
left_track = mock('left_track')
|
70
|
-
right_track = mock('right_track')
|
71
|
-
steps_per_degree = 5.0 / 90.0
|
72
|
-
rover = Rover.new(left_track, right_track, nil, steps_per_degree)
|
73
|
-
|
74
|
-
left_track.expects(:step).with(+5)
|
75
|
-
right_track.expects(:step).with(-5)
|
76
|
-
|
77
|
-
left_track.stubs(:moving?).returns(false)
|
78
|
-
right_track.stubs(:moving?).returns(false)
|
79
|
-
|
80
|
-
rover.right(90)
|
81
|
-
end
|
82
|
-
|
83
|
-
def test_should_step_left_track_backwards_five_steps_and_right_track_forwards_five_steps
|
84
|
-
left_track = mock('left_track')
|
85
|
-
right_track = mock('right_track')
|
86
|
-
steps_per_degree = 5.0 / 90.0
|
87
|
-
rover = Rover.new(left_track, right_track, nil, steps_per_degree)
|
88
|
-
|
89
|
-
left_track.expects(:step).with(-5)
|
90
|
-
right_track.expects(:step).with(+5)
|
91
|
-
|
92
|
-
left_track.stubs(:moving?).returns(false)
|
93
|
-
right_track.stubs(:moving?).returns(false)
|
94
|
-
|
95
|
-
rover.left(90)
|
96
|
-
end
|
97
|
-
|
98
|
-
end
|
@@ -1,84 +0,0 @@
|
|
1
|
-
require File.expand_path('../acceptance_test_helper', __FILE__)
|
2
|
-
require 'mocha/setup'
|
3
|
-
require 'execution_point'
|
4
|
-
|
5
|
-
class MochaTestResultTest < Mocha::TestCase
|
6
|
-
|
7
|
-
include AcceptanceTest
|
8
|
-
|
9
|
-
def setup
|
10
|
-
setup_acceptance_test
|
11
|
-
end
|
12
|
-
|
13
|
-
def teardown
|
14
|
-
teardown_acceptance_test
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_should_include_expectation_verification_in_assertion_count
|
18
|
-
test_result = run_as_test do
|
19
|
-
object = mock()
|
20
|
-
object.expects(:message)
|
21
|
-
object.message
|
22
|
-
end
|
23
|
-
assert_equal 1, test_result.assertion_count
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_should_include_assertions_in_assertion_count
|
27
|
-
test_result = run_as_test do
|
28
|
-
assert true
|
29
|
-
end
|
30
|
-
assert_equal 1, test_result.assertion_count
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_should_not_include_stubbing_expectation_verification_in_assertion_count
|
34
|
-
test_result = run_as_test do
|
35
|
-
object = mock()
|
36
|
-
object.stubs(:message)
|
37
|
-
object.message
|
38
|
-
end
|
39
|
-
assert_equal 0, test_result.assertion_count
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_should_include_expectation_verification_failure_in_failure_count
|
43
|
-
test_result = run_as_test do
|
44
|
-
object = mock()
|
45
|
-
object.expects(:message)
|
46
|
-
end
|
47
|
-
assert_equal 1, test_result.failure_count
|
48
|
-
end
|
49
|
-
|
50
|
-
def test_should_include_unexpected_verification_failure_in_failure_count
|
51
|
-
test_result = run_as_test do
|
52
|
-
object = mock()
|
53
|
-
object.message
|
54
|
-
end
|
55
|
-
assert_equal 1, test_result.failure_count
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_should_include_assertion_failure_in_failure_count
|
59
|
-
test_result = run_as_test do
|
60
|
-
flunk
|
61
|
-
end
|
62
|
-
assert_equal 1, test_result.failure_count
|
63
|
-
end
|
64
|
-
|
65
|
-
def test_should_display_backtrace_indicating_line_number_where_unexpected_method_was_called
|
66
|
-
execution_point = nil
|
67
|
-
test_result = run_as_test do
|
68
|
-
object = mock()
|
69
|
-
execution_point = ExecutionPoint.current; object.message
|
70
|
-
end
|
71
|
-
assert_equal 1, test_result.failure_count
|
72
|
-
assert_equal execution_point, ExecutionPoint.new(test_result.failures[0].location)
|
73
|
-
end
|
74
|
-
|
75
|
-
def test_should_display_backtrace_indicating_line_number_where_failing_assertion_was_called
|
76
|
-
execution_point = nil
|
77
|
-
test_result = run_as_test do
|
78
|
-
execution_point = ExecutionPoint.current; flunk
|
79
|
-
end
|
80
|
-
assert_equal 1, test_result.failure_count
|
81
|
-
assert_equal execution_point, ExecutionPoint.new(test_result.failures[0].location)
|
82
|
-
end
|
83
|
-
|
84
|
-
end
|