mocha 1.11.2 → 1.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CONTRIBUTING.md +1 -1
- data/README.md +28 -30
- data/RELEASE.md +25 -0
- data/Rakefile +6 -1
- data/lib/mocha/cardinality.rb +30 -27
- data/lib/mocha/expectation.rb +24 -24
- data/lib/mocha/mock.rb +1 -1
- data/lib/mocha/mockery.rb +9 -22
- data/lib/mocha/state_machine.rb +30 -38
- data/lib/mocha/version.rb +1 -1
- data/mocha.gemspec +3 -1
- metadata +5 -192
- data/docs/CNAME +0 -1
- data/docs/Mocha.html +0 -254
- data/docs/Mocha/API.html +0 -1285
- data/docs/Mocha/ClassMethods.html +0 -264
- data/docs/Mocha/Configuration.html +0 -1525
- data/docs/Mocha/Expectation.html +0 -2862
- data/docs/Mocha/ExpectationError.html +0 -152
- data/docs/Mocha/ExpectationErrorFactory.html +0 -260
- data/docs/Mocha/Hooks.html +0 -370
- data/docs/Mocha/Integration.html +0 -125
- data/docs/Mocha/Integration/MiniTest.html +0 -123
- data/docs/Mocha/Integration/MiniTest/Adapter.html +0 -164
- data/docs/Mocha/Integration/TestUnit.html +0 -123
- data/docs/Mocha/Integration/TestUnit/Adapter.html +0 -164
- data/docs/Mocha/Mock.html +0 -1210
- data/docs/Mocha/ObjectMethods.html +0 -765
- data/docs/Mocha/ParameterMatchers.html +0 -2949
- data/docs/Mocha/ParameterMatchers/AllOf.html +0 -153
- data/docs/Mocha/ParameterMatchers/AnyOf.html +0 -153
- data/docs/Mocha/ParameterMatchers/AnyParameters.html +0 -153
- data/docs/Mocha/ParameterMatchers/Anything.html +0 -153
- data/docs/Mocha/ParameterMatchers/Base.html +0 -441
- data/docs/Mocha/ParameterMatchers/Equals.html +0 -153
- data/docs/Mocha/ParameterMatchers/EquivalentUri.html +0 -153
- data/docs/Mocha/ParameterMatchers/HasEntries.html +0 -153
- data/docs/Mocha/ParameterMatchers/HasEntry.html +0 -153
- data/docs/Mocha/ParameterMatchers/HasKey.html +0 -153
- data/docs/Mocha/ParameterMatchers/HasValue.html +0 -153
- data/docs/Mocha/ParameterMatchers/Includes.html +0 -153
- data/docs/Mocha/ParameterMatchers/InstanceOf.html +0 -153
- data/docs/Mocha/ParameterMatchers/IsA.html +0 -153
- data/docs/Mocha/ParameterMatchers/KindOf.html +0 -153
- data/docs/Mocha/ParameterMatchers/Not.html +0 -153
- data/docs/Mocha/ParameterMatchers/Optionally.html +0 -153
- data/docs/Mocha/ParameterMatchers/RegexpMatches.html +0 -153
- data/docs/Mocha/ParameterMatchers/RespondsWith.html +0 -153
- data/docs/Mocha/ParameterMatchers/YamlEquivalent.html +0 -153
- data/docs/Mocha/Sequence.html +0 -149
- data/docs/Mocha/StateMachine.html +0 -527
- data/docs/Mocha/StateMachine/State.html +0 -140
- data/docs/Mocha/StateMachine/StatePredicate.html +0 -140
- data/docs/Mocha/StubbingError.html +0 -150
- data/docs/_index.html +0 -519
- data/docs/class_list.html +0 -51
- data/docs/css/common.css +0 -1
- data/docs/css/full_list.css +0 -58
- data/docs/css/style.css +0 -496
- data/docs/file.COPYING.html +0 -81
- data/docs/file.MIT-LICENSE.html +0 -85
- data/docs/file.README.html +0 -448
- data/docs/file.RELEASE.html +0 -1028
- data/docs/file_list.html +0 -71
- data/docs/frames.html +0 -17
- data/docs/index.html +0 -448
- data/docs/js/app.js +0 -303
- data/docs/js/full_list.js +0 -216
- data/docs/js/jquery.js +0 -4
- data/docs/method_list.html +0 -651
- data/docs/top-level-namespace.html +0 -118
- data/test/acceptance/acceptance_test_helper.rb +0 -42
- data/test/acceptance/bug_18914_test.rb +0 -37
- data/test/acceptance/bug_21465_test.rb +0 -31
- data/test/acceptance/bug_21563_test.rb +0 -22
- data/test/acceptance/display_matching_invocations_alongside_expectations_test.rb +0 -69
- data/test/acceptance/exception_rescue_test.rb +0 -53
- data/test/acceptance/expectations_on_multiple_methods_test.rb +0 -55
- data/test/acceptance/expected_invocation_count_test.rb +0 -229
- data/test/acceptance/failure_messages_test.rb +0 -77
- data/test/acceptance/issue_272_test.rb +0 -50
- data/test/acceptance/issue_457_test.rb +0 -31
- data/test/acceptance/issue_65_test.rb +0 -64
- data/test/acceptance/issue_70_test.rb +0 -53
- data/test/acceptance/mocha_example_test.rb +0 -106
- data/test/acceptance/mocha_test_result_test.rb +0 -83
- data/test/acceptance/mock_built_with_first_argument_type_being_string_test.rb +0 -98
- data/test/acceptance/mock_test.rb +0 -191
- data/test/acceptance/mocked_methods_dispatch_test.rb +0 -75
- data/test/acceptance/multiple_expectations_failure_message_test.rb +0 -66
- data/test/acceptance/multiple_yielding_test.rb +0 -59
- data/test/acceptance/optional_parameters_test.rb +0 -67
- data/test/acceptance/parameter_matcher_test.rb +0 -299
- data/test/acceptance/partial_mocks_test.rb +0 -44
- data/test/acceptance/prepend_test.rb +0 -86
- data/test/acceptance/prevent_use_of_mocha_outside_test_test.rb +0 -76
- data/test/acceptance/raise_exception_test.rb +0 -36
- data/test/acceptance/return_value_test.rb +0 -49
- data/test/acceptance/sequence_test.rb +0 -189
- data/test/acceptance/states_test.rb +0 -71
- data/test/acceptance/stub_any_instance_method_defined_on_superclass_test.rb +0 -64
- data/test/acceptance/stub_any_instance_method_test.rb +0 -301
- data/test/acceptance/stub_class_method_defined_on_active_record_association_proxy_test.rb +0 -105
- 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 -73
- data/test/acceptance/stub_class_method_defined_on_superclass_test.rb +0 -144
- data/test/acceptance/stub_everything_test.rb +0 -53
- data/test/acceptance/stub_instance_method_defined_on_active_record_association_proxy_test.rb +0 -91
- data/test/acceptance/stub_instance_method_defined_on_class_and_aliased_test.rb +0 -67
- data/test/acceptance/stub_instance_method_defined_on_class_test.rb +0 -67
- data/test/acceptance/stub_instance_method_defined_on_kernel_module_test.rb +0 -136
- data/test/acceptance/stub_instance_method_defined_on_module_test.rb +0 -76
- 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 -67
- data/test/acceptance/stub_instance_method_defined_on_superclass_test.rb +0 -70
- data/test/acceptance/stub_method_defined_on_module_and_aliased_test.rb +0 -38
- data/test/acceptance/stub_module_method_test.rb +0 -200
- data/test/acceptance/stub_test.rb +0 -49
- data/test/acceptance/stubba_example_test.rb +0 -103
- data/test/acceptance/stubba_test_result_test.rb +0 -71
- data/test/acceptance/stubbing_error_backtrace_test.rb +0 -63
- data/test/acceptance/stubbing_frozen_object_test.rb +0 -88
- data/test/acceptance/stubbing_method_accepting_block_parameter_test.rb +0 -52
- data/test/acceptance/stubbing_method_unnecessarily_test.rb +0 -63
- data/test/acceptance/stubbing_nil_test.rb +0 -60
- data/test/acceptance/stubbing_non_existent_any_instance_method_test.rb +0 -157
- data/test/acceptance/stubbing_non_existent_class_method_test.rb +0 -157
- data/test/acceptance/stubbing_non_existent_instance_method_test.rb +0 -145
- data/test/acceptance/stubbing_non_public_any_instance_method_test.rb +0 -128
- data/test/acceptance/stubbing_non_public_class_method_test.rb +0 -163
- data/test/acceptance/stubbing_non_public_instance_method_test.rb +0 -141
- data/test/acceptance/stubbing_on_non_mock_object_test.rb +0 -70
- data/test/acceptance/stubbing_same_class_method_on_parent_and_child_classes_test.rb +0 -33
- data/test/acceptance/throw_test.rb +0 -42
- data/test/acceptance/unexpected_invocation_test.rb +0 -23
- data/test/acceptance/unstubbing_test.rb +0 -194
- data/test/acceptance/yielding_test.rb +0 -80
- 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 -178
- data/test/integration/test_unit_test.rb +0 -8
- data/test/method_definer.rb +0 -16
- data/test/mini_test_result.rb +0 -96
- data/test/minitest_result.rb +0 -48
- data/test/simple_counter.rb +0 -11
- data/test/test_helper.rb +0 -58
- data/test/test_runner.rb +0 -58
- data/test/test_unit_result.rb +0 -22
- data/test/unit/any_instance_method_test.rb +0 -175
- data/test/unit/array_inspect_test.rb +0 -14
- data/test/unit/backtrace_filter_test.rb +0 -17
- data/test/unit/cardinality_test.rb +0 -72
- data/test/unit/central_test.rb +0 -98
- data/test/unit/change_state_side_effect_test.rb +0 -37
- data/test/unit/class_methods_test.rb +0 -69
- data/test/unit/configuration_test.rb +0 -37
- data/test/unit/date_time_inspect_test.rb +0 -19
- data/test/unit/exception_raiser_test.rb +0 -45
- data/test/unit/expectation_list_test.rb +0 -82
- data/test/unit/expectation_test.rb +0 -504
- data/test/unit/hash_inspect_test.rb +0 -14
- data/test/unit/hooks_test.rb +0 -35
- data/test/unit/in_state_ordering_constraint_test.rb +0 -39
- data/test/unit/instance_method_test.rb +0 -282
- data/test/unit/method_matcher_test.rb +0 -26
- data/test/unit/mock_test.rb +0 -372
- data/test/unit/mockery_test.rb +0 -171
- data/test/unit/module_methods_test.rb +0 -16
- data/test/unit/object_inspect_test.rb +0 -60
- data/test/unit/object_methods_test.rb +0 -63
- data/test/unit/parameter_matchers/all_of_test.rb +0 -24
- data/test/unit/parameter_matchers/any_of_test.rb +0 -24
- data/test/unit/parameter_matchers/anything_test.rb +0 -19
- data/test/unit/parameter_matchers/equals_test.rb +0 -23
- data/test/unit/parameter_matchers/equivalent_uri_test.rb +0 -41
- data/test/unit/parameter_matchers/has_entries_test.rb +0 -51
- data/test/unit/parameter_matchers/has_entry_test.rb +0 -128
- data/test/unit/parameter_matchers/has_key_test.rb +0 -54
- data/test/unit/parameter_matchers/has_value_test.rb +0 -55
- data/test/unit/parameter_matchers/includes_test.rb +0 -106
- data/test/unit/parameter_matchers/instance_of_test.rb +0 -23
- data/test/unit/parameter_matchers/is_a_test.rb +0 -23
- data/test/unit/parameter_matchers/kind_of_test.rb +0 -23
- data/test/unit/parameter_matchers/not_test.rb +0 -24
- data/test/unit/parameter_matchers/regexp_matches_test.rb +0 -45
- data/test/unit/parameter_matchers/responds_with_test.rb +0 -38
- data/test/unit/parameter_matchers/stub_matcher.rb +0 -23
- data/test/unit/parameter_matchers/yaml_equivalent_test.rb +0 -23
- data/test/unit/parameters_matcher_test.rb +0 -119
- data/test/unit/receivers_test.rb +0 -96
- data/test/unit/return_values_test.rb +0 -66
- data/test/unit/sequence_test.rb +0 -100
- data/test/unit/single_return_value_test.rb +0 -17
- data/test/unit/state_machine_test.rb +0 -96
- data/test/unit/string_inspect_test.rb +0 -9
- data/test/unit/thrower_test.rb +0 -23
- data/test/unit/yield_parameters_test.rb +0 -73
@@ -1,98 +0,0 @@
|
|
1
|
-
require File.expand_path('../acceptance_test_helper', __FILE__)
|
2
|
-
require 'deprecation_disabler'
|
3
|
-
|
4
|
-
class MockBuiltWithFirstArgumentTypeBeingStringTest < Mocha::TestCase
|
5
|
-
include AcceptanceTest
|
6
|
-
|
7
|
-
def setup
|
8
|
-
setup_acceptance_test
|
9
|
-
end
|
10
|
-
|
11
|
-
def teardown
|
12
|
-
teardown_acceptance_test
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_mock_built_with_single_symbol_argument_with_satisfied_expectation
|
16
|
-
test_result = run_as_test do
|
17
|
-
DeprecationDisabler.disable_deprecations do
|
18
|
-
m = mock(:my_method)
|
19
|
-
assert_nil m.my_method
|
20
|
-
end
|
21
|
-
expected_warning = 'Explicitly include `my_method` in Hash of expected methods vs return values, e.g. `mock(:my_method => nil)`.'
|
22
|
-
assert_equal expected_warning, Mocha::Deprecation.messages.last
|
23
|
-
end
|
24
|
-
assert_passed(test_result)
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_mock_built_with_single_symbol_argument_with_unsatisfied_expectation
|
28
|
-
test_result = run_as_test do
|
29
|
-
DeprecationDisabler.disable_deprecations do
|
30
|
-
mock(:my_method)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
assert_failed(test_result)
|
34
|
-
assert(test_result.failure_message_lines.any? do |line|
|
35
|
-
line[/expected exactly once, invoked never\: #<Mock\:0x[0-9a-f]+>\.my_method\(any_parameters\)/]
|
36
|
-
end)
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_stub_built_with_single_symbol_argument
|
40
|
-
test_result = run_as_test do
|
41
|
-
DeprecationDisabler.disable_deprecations do
|
42
|
-
s = stub(:my_method)
|
43
|
-
assert_nil s.my_method
|
44
|
-
end
|
45
|
-
expected_warning = 'Explicitly include `my_method` in Hash of stubbed methods vs return values, e.g. `stub(:my_method => nil)`.'
|
46
|
-
assert_equal expected_warning, Mocha::Deprecation.messages.last
|
47
|
-
end
|
48
|
-
assert_passed(test_result)
|
49
|
-
end
|
50
|
-
|
51
|
-
def test_mock_built_with_first_argument_a_symbol_and_second_argument_a_hash
|
52
|
-
test_result = run_as_test do
|
53
|
-
DeprecationDisabler.disable_deprecations do
|
54
|
-
s = mock(:my_method, :another_method => 123)
|
55
|
-
assert_nil s.my_method
|
56
|
-
end
|
57
|
-
expected_warning = 'In this case the 2nd argument for `mock(:#my_method, ...)` is ignored, but in the future a Hash of expected methods vs return values will be respected.'
|
58
|
-
assert Mocha::Deprecation.messages.last(2).include?(expected_warning)
|
59
|
-
end
|
60
|
-
assert_passed(test_result)
|
61
|
-
end
|
62
|
-
|
63
|
-
def test_stub_built_with_first_argument_a_symbol_and_second_argument_a_hash
|
64
|
-
test_result = run_as_test do
|
65
|
-
DeprecationDisabler.disable_deprecations do
|
66
|
-
s = stub(:my_method, :another_method => 123)
|
67
|
-
assert_nil s.my_method
|
68
|
-
end
|
69
|
-
expected_warning = 'In this case the 2nd argument for `stub(:#my_method, ...)` is ignored, but in the future a Hash of stubbed methods vs return values will be respected.'
|
70
|
-
assert Mocha::Deprecation.messages.last(2).include?(expected_warning)
|
71
|
-
end
|
72
|
-
assert_passed(test_result)
|
73
|
-
end
|
74
|
-
|
75
|
-
def test_stub_everything_built_with_single_symbol_argument
|
76
|
-
test_result = run_as_test do
|
77
|
-
DeprecationDisabler.disable_deprecations do
|
78
|
-
s = stub_everything(:my_method)
|
79
|
-
assert_nil s.my_method
|
80
|
-
end
|
81
|
-
expected_warning = 'Explicitly include `my_method` in Hash of stubbed methods vs return values, e.g. `stub_everything(:my_method => nil)`.'
|
82
|
-
assert_equal expected_warning, Mocha::Deprecation.messages.last
|
83
|
-
end
|
84
|
-
assert_passed(test_result)
|
85
|
-
end
|
86
|
-
|
87
|
-
def test_stub_everything_built_with_first_argument_a_symbol_and_second_argument_a_hash
|
88
|
-
test_result = run_as_test do
|
89
|
-
DeprecationDisabler.disable_deprecations do
|
90
|
-
s = stub_everything(:my_method, :another_method => 123)
|
91
|
-
assert_nil s.my_method
|
92
|
-
end
|
93
|
-
expected_warning = 'In this case the 2nd argument for `stub_everything(:#my_method, ...)` is ignored, but in the future a Hash of stubbed methods vs return values will be respected.' # rubocop:disable Metrics/LineLength
|
94
|
-
assert Mocha::Deprecation.messages.last(2).include?(expected_warning)
|
95
|
-
end
|
96
|
-
assert_passed(test_result)
|
97
|
-
end
|
98
|
-
end
|
@@ -1,191 +0,0 @@
|
|
1
|
-
require File.expand_path('../acceptance_test_helper', __FILE__)
|
2
|
-
require 'mocha/configuration'
|
3
|
-
require 'mocha/deprecation'
|
4
|
-
require 'deprecation_disabler'
|
5
|
-
|
6
|
-
class MockTest < Mocha::TestCase
|
7
|
-
include AcceptanceTest
|
8
|
-
include Mocha
|
9
|
-
|
10
|
-
def setup
|
11
|
-
setup_acceptance_test
|
12
|
-
end
|
13
|
-
|
14
|
-
def teardown
|
15
|
-
teardown_acceptance_test
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_should_build_mock_and_explicitly_add_an_expectation_which_is_satisfied
|
19
|
-
test_result = run_as_test do
|
20
|
-
foo = mock
|
21
|
-
foo.expects(:bar)
|
22
|
-
foo.bar
|
23
|
-
end
|
24
|
-
assert_passed(test_result)
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_should_build_mock_and_explicitly_add_an_expectation_which_is_not_satisfied
|
28
|
-
test_result = run_as_test do
|
29
|
-
foo = mock
|
30
|
-
foo.expects(:bar)
|
31
|
-
end
|
32
|
-
assert_failed(test_result)
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_should_build_string_named_mock_and_explicitly_add_an_expectation_which_is_satisfied
|
36
|
-
test_result = run_as_test do
|
37
|
-
foo = mock('foo')
|
38
|
-
foo.expects(:bar)
|
39
|
-
foo.bar
|
40
|
-
end
|
41
|
-
assert_passed(test_result)
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_should_build_symbol_named_mock_and_explicitly_add_an_expectation_which_is_satisfied
|
45
|
-
test_result = run_as_test do
|
46
|
-
Mocha::Configuration.override(:reinstate_undocumented_behaviour_from_v1_9 => false) do
|
47
|
-
DeprecationDisabler.disable_deprecations do
|
48
|
-
foo = mock(:foo)
|
49
|
-
foo.expects(:bar)
|
50
|
-
foo.bar
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
assert_passed(test_result)
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_should_build_string_named_mock_and_explicitly_add_an_expectation_which_is_not_satisfied
|
58
|
-
test_result = run_as_test do
|
59
|
-
foo = mock('foo')
|
60
|
-
foo.expects(:bar)
|
61
|
-
end
|
62
|
-
assert_failed(test_result)
|
63
|
-
end
|
64
|
-
|
65
|
-
def test_should_build_symbol_named_mock_and_explicitly_add_an_expectation_which_is_not_satisfied
|
66
|
-
test_result = run_as_test do
|
67
|
-
DeprecationDisabler.disable_deprecations do
|
68
|
-
foo = mock(:foo)
|
69
|
-
foo.expects(:bar)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
assert_failed(test_result)
|
73
|
-
end
|
74
|
-
|
75
|
-
def test_should_build_mock_incorporating_two_expectations_which_are_satisifed
|
76
|
-
test_result = run_as_test do
|
77
|
-
foo = mock(:bar => 'bar', :baz => 'baz')
|
78
|
-
foo.bar
|
79
|
-
foo.baz
|
80
|
-
end
|
81
|
-
assert_passed(test_result)
|
82
|
-
end
|
83
|
-
|
84
|
-
def test_should_build_mock_incorporating_two_expectations_the_first_of_which_is_not_satisifed
|
85
|
-
test_result = run_as_test do
|
86
|
-
foo = mock(:bar => 'bar', :baz => 'baz')
|
87
|
-
foo.baz
|
88
|
-
end
|
89
|
-
assert_failed(test_result)
|
90
|
-
end
|
91
|
-
|
92
|
-
def test_should_build_mock_incorporating_two_expectations_the_second_of_which_is_not_satisifed
|
93
|
-
test_result = run_as_test do
|
94
|
-
foo = mock(:bar => 'bar', :baz => 'baz')
|
95
|
-
foo.bar
|
96
|
-
end
|
97
|
-
assert_failed(test_result)
|
98
|
-
end
|
99
|
-
|
100
|
-
def test_should_build_string_named_mock_incorporating_two_expectations_which_are_satisifed
|
101
|
-
test_result = run_as_test do
|
102
|
-
foo = mock('foo', :bar => 'bar', :baz => 'baz')
|
103
|
-
foo.bar
|
104
|
-
foo.baz
|
105
|
-
end
|
106
|
-
assert_passed(test_result)
|
107
|
-
end
|
108
|
-
|
109
|
-
def test_should_build_symbol_named_mock_incorporating_two_expectations_which_are_satisifed
|
110
|
-
test_result = run_as_test do
|
111
|
-
Mocha::Configuration.override(:reinstate_undocumented_behaviour_from_v1_9 => false) do
|
112
|
-
DeprecationDisabler.disable_deprecations do
|
113
|
-
foo = mock(:foo, :bar => 'bar', :baz => 'baz')
|
114
|
-
foo.bar
|
115
|
-
foo.baz
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
119
|
-
assert_passed(test_result)
|
120
|
-
end
|
121
|
-
|
122
|
-
def test_should_build_string_named_mock_incorporating_two_expectations_the_first_of_which_is_not_satisifed
|
123
|
-
test_result = run_as_test do
|
124
|
-
foo = mock('foo', :bar => 'bar', :baz => 'baz')
|
125
|
-
foo.baz
|
126
|
-
end
|
127
|
-
assert_failed(test_result)
|
128
|
-
end
|
129
|
-
|
130
|
-
def test_should_build_symbol_named_mock_incorporating_two_expectations_the_first_of_which_is_not_satisifed
|
131
|
-
test_result = run_as_test do
|
132
|
-
DeprecationDisabler.disable_deprecations do
|
133
|
-
foo = mock(:foo, :bar => 'bar', :baz => 'baz')
|
134
|
-
foo.baz
|
135
|
-
end
|
136
|
-
end
|
137
|
-
assert_failed(test_result)
|
138
|
-
end
|
139
|
-
|
140
|
-
def test_should_build_string_named_mock_incorporating_two_expectations_the_second_of_which_is_not_satisifed
|
141
|
-
test_result = run_as_test do
|
142
|
-
foo = mock('foo', :bar => 'bar', :baz => 'baz')
|
143
|
-
foo.bar
|
144
|
-
end
|
145
|
-
assert_failed(test_result)
|
146
|
-
end
|
147
|
-
|
148
|
-
def test_should_build_symbol_named_mock_incorporating_two_expectations_the_second_of_which_is_not_satisifed
|
149
|
-
test_result = run_as_test do
|
150
|
-
DeprecationDisabler.disable_deprecations do
|
151
|
-
foo = mock(:foo, :bar => 'bar', :baz => 'baz')
|
152
|
-
foo.bar
|
153
|
-
end
|
154
|
-
end
|
155
|
-
assert_failed(test_result)
|
156
|
-
end
|
157
|
-
|
158
|
-
class Foo
|
159
|
-
class << self
|
160
|
-
attr_accessor :logger
|
161
|
-
end
|
162
|
-
|
163
|
-
def use_the_mock
|
164
|
-
self.class.logger.log('Foo was here')
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
# rubocop:disable Metrics/AbcSize
|
169
|
-
def test_should_display_deprecation_warning_if_mock_receives_invocations_in_another_test
|
170
|
-
use_mock_test_result = run_as_test do
|
171
|
-
Foo.logger = mock('Logger')
|
172
|
-
Foo.logger.expects(:log).with('Foo was here')
|
173
|
-
Foo.new.use_the_mock
|
174
|
-
end
|
175
|
-
assert_passed(use_mock_test_result)
|
176
|
-
|
177
|
-
reuse_mock_test_result = run_as_test do
|
178
|
-
DeprecationDisabler.disable_deprecations do
|
179
|
-
Foo.logger.expects(:log).with('Foo was here')
|
180
|
-
Foo.new.use_the_mock
|
181
|
-
end
|
182
|
-
end
|
183
|
-
assert_passed(reuse_mock_test_result)
|
184
|
-
assert message = Deprecation.messages.last
|
185
|
-
assert message.include?('#<Mock:Logger> was instantiated in one test but it is receiving invocations within another test.')
|
186
|
-
assert message.include?('This can lead to unintended interactions between tests and hence unexpected test failures.')
|
187
|
-
assert message.include?('Ensure that every test correctly cleans up any state that it introduces.')
|
188
|
-
assert message.include?('A Mocha::StubbingError will be raised in this scenario in the future.')
|
189
|
-
end
|
190
|
-
# rubocop:enable Metrics/AbcSize
|
191
|
-
end
|
@@ -1,75 +0,0 @@
|
|
1
|
-
require File.expand_path('../acceptance_test_helper', __FILE__)
|
2
|
-
|
3
|
-
class MockedMethodDispatchTest < Mocha::TestCase
|
4
|
-
include AcceptanceTest
|
5
|
-
|
6
|
-
def setup
|
7
|
-
setup_acceptance_test
|
8
|
-
end
|
9
|
-
|
10
|
-
def teardown
|
11
|
-
teardown_acceptance_test
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_should_find_latest_matching_expectation
|
15
|
-
test_result = run_as_test do
|
16
|
-
mock = mock()
|
17
|
-
mock.stubs(:method).returns(1)
|
18
|
-
mock.stubs(:method).returns(2)
|
19
|
-
assert_equal 2, mock.method
|
20
|
-
assert_equal 2, mock.method
|
21
|
-
assert_equal 2, mock.method
|
22
|
-
end
|
23
|
-
assert_passed(test_result)
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_should_find_latest_expectation_which_has_not_stopped_matching
|
27
|
-
test_result = run_as_test do
|
28
|
-
mock = mock()
|
29
|
-
mock.stubs(:method).returns(1)
|
30
|
-
mock.stubs(:method).once.returns(2)
|
31
|
-
assert_equal 2, mock.method
|
32
|
-
assert_equal 1, mock.method
|
33
|
-
assert_equal 1, mock.method
|
34
|
-
end
|
35
|
-
assert_passed(test_result)
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_should_keep_finding_later_stub_and_so_never_satisfy_earlier_expectation
|
39
|
-
test_result = run_as_test do
|
40
|
-
mock = mock()
|
41
|
-
mock.expects(:method).returns(1)
|
42
|
-
mock.stubs(:method).returns(2)
|
43
|
-
assert_equal 2, mock.method
|
44
|
-
assert_equal 2, mock.method
|
45
|
-
assert_equal 2, mock.method
|
46
|
-
end
|
47
|
-
assert_failed(test_result)
|
48
|
-
end
|
49
|
-
|
50
|
-
def test_should_find_later_expectation_until_it_stops_matching_then_find_earlier_stub
|
51
|
-
test_result = run_as_test do
|
52
|
-
mock = mock()
|
53
|
-
mock.stubs(:method).returns(1)
|
54
|
-
mock.expects(:method).returns(2)
|
55
|
-
assert_equal 2, mock.method
|
56
|
-
assert_equal 1, mock.method
|
57
|
-
assert_equal 1, mock.method
|
58
|
-
end
|
59
|
-
assert_passed(test_result)
|
60
|
-
end
|
61
|
-
|
62
|
-
def test_should_find_latest_expectation_with_range_of_expected_invocation_count_which_has_not_stopped_matching
|
63
|
-
test_result = run_as_test do
|
64
|
-
mock = mock()
|
65
|
-
mock.stubs(:method).returns(1)
|
66
|
-
mock.stubs(:method).times(2..3).returns(2)
|
67
|
-
assert_equal 2, mock.method
|
68
|
-
assert_equal 2, mock.method
|
69
|
-
assert_equal 2, mock.method
|
70
|
-
assert_equal 1, mock.method
|
71
|
-
assert_equal 1, mock.method
|
72
|
-
end
|
73
|
-
assert_passed(test_result)
|
74
|
-
end
|
75
|
-
end
|
@@ -1,66 +0,0 @@
|
|
1
|
-
require File.expand_path('../acceptance_test_helper', __FILE__)
|
2
|
-
|
3
|
-
class FailureMessageTest < Mocha::TestCase
|
4
|
-
include AcceptanceTest
|
5
|
-
|
6
|
-
def setup
|
7
|
-
setup_acceptance_test
|
8
|
-
end
|
9
|
-
|
10
|
-
def teardown
|
11
|
-
teardown_acceptance_test
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_should_include_unexpected_invocation_in_unsatisfied_expectation_message
|
15
|
-
test_result = run_as_test do
|
16
|
-
mock = mock('mock')
|
17
|
-
mock.expects(:method_one).once
|
18
|
-
2.times { mock.method_one }
|
19
|
-
end
|
20
|
-
assert_failed(test_result)
|
21
|
-
assert_equal [
|
22
|
-
'unexpected invocation: #<Mock:mock>.method_one()',
|
23
|
-
'unsatisfied expectations:',
|
24
|
-
'- expected exactly once, invoked twice: #<Mock:mock>.method_one(any_parameters)'
|
25
|
-
], test_result.failure_message_lines
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_should_report_satisfied_expectations_as_well_as_unsatisfied_expectations
|
29
|
-
test_result = run_as_test do
|
30
|
-
mock = mock('mock')
|
31
|
-
mock.expects(:method_one).once
|
32
|
-
mock.expects(:method_two).twice
|
33
|
-
1.times { mock.method_one }
|
34
|
-
1.times { mock.method_two }
|
35
|
-
end
|
36
|
-
assert_failed(test_result)
|
37
|
-
assert_equal [
|
38
|
-
'not all expectations were satisfied',
|
39
|
-
'unsatisfied expectations:',
|
40
|
-
'- expected exactly twice, invoked once: #<Mock:mock>.method_two(any_parameters)',
|
41
|
-
'satisfied expectations:',
|
42
|
-
'- expected exactly once, invoked once: #<Mock:mock>.method_one(any_parameters)'
|
43
|
-
], test_result.failure_message_lines
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_should_report_multiple_satisfied_expectations
|
47
|
-
test_result = run_as_test do
|
48
|
-
mock = mock('mock')
|
49
|
-
mock.expects(:method_one).once
|
50
|
-
mock.expects(:method_two).twice
|
51
|
-
mock.expects(:method_three).times(3)
|
52
|
-
1.times { mock.method_one }
|
53
|
-
2.times { mock.method_two }
|
54
|
-
2.times { mock.method_three }
|
55
|
-
end
|
56
|
-
assert_failed(test_result)
|
57
|
-
assert_equal [
|
58
|
-
'not all expectations were satisfied',
|
59
|
-
'unsatisfied expectations:',
|
60
|
-
'- expected exactly 3 times, invoked twice: #<Mock:mock>.method_three(any_parameters)',
|
61
|
-
'satisfied expectations:',
|
62
|
-
'- expected exactly twice, invoked twice: #<Mock:mock>.method_two(any_parameters)',
|
63
|
-
'- expected exactly once, invoked once: #<Mock:mock>.method_one(any_parameters)'
|
64
|
-
], test_result.failure_message_lines
|
65
|
-
end
|
66
|
-
end
|
@@ -1,59 +0,0 @@
|
|
1
|
-
require File.expand_path('../acceptance_test_helper', __FILE__)
|
2
|
-
require 'mocha/configuration'
|
3
|
-
|
4
|
-
class MultipleYieldingTest < Mocha::TestCase
|
5
|
-
include AcceptanceTest
|
6
|
-
|
7
|
-
def setup
|
8
|
-
setup_acceptance_test
|
9
|
-
end
|
10
|
-
|
11
|
-
def teardown
|
12
|
-
teardown_acceptance_test
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_yields_values_multiple_times_when_stubbed_method_is_invoked
|
16
|
-
test_result = run_as_test do
|
17
|
-
m = mock('m')
|
18
|
-
m.stubs(:foo).multiple_yields([1], [2, 3])
|
19
|
-
yielded = []
|
20
|
-
m.foo { |*args| yielded << args }
|
21
|
-
assert_equal [[1], [2, 3]], yielded
|
22
|
-
end
|
23
|
-
assert_passed(test_result)
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_yields_values_multiple_times_when_multiple_yields_arguments_are_not_arrays
|
27
|
-
test_result = run_as_test do
|
28
|
-
m = mock('m')
|
29
|
-
m.stubs(:foo).multiple_yields(1, { :b => 2 }, '3')
|
30
|
-
yielded = []
|
31
|
-
m.foo { |*args| yielded << args }
|
32
|
-
assert_equal [[1], [{ :b => 2 }], ['3']], yielded
|
33
|
-
end
|
34
|
-
assert_passed(test_result)
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_raises_local_jump_error_if_instructed_to_multiple_yield_but_no_block_given
|
38
|
-
test_result = run_as_test do
|
39
|
-
Mocha::Configuration.override(:reinstate_undocumented_behaviour_from_v1_9 => false) do
|
40
|
-
m = mock('m')
|
41
|
-
m.stubs(:foo).multiple_yields([])
|
42
|
-
assert_raises(LocalJumpError) { m.foo }
|
43
|
-
end
|
44
|
-
end
|
45
|
-
assert_passed(test_result)
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_yields_different_values_on_consecutive_invocations
|
49
|
-
test_result = run_as_test do
|
50
|
-
m = mock('m')
|
51
|
-
m.stubs(:foo).multiple_yields([0], [1, 2]).then.multiple_yields([3], [4, 5])
|
52
|
-
yielded = []
|
53
|
-
m.foo { |*args| yielded << args }
|
54
|
-
m.foo { |*args| yielded << args }
|
55
|
-
assert_equal [[0], [1, 2], [3], [4, 5]], yielded
|
56
|
-
end
|
57
|
-
assert_passed(test_result)
|
58
|
-
end
|
59
|
-
end
|