mocha 1.8.0 → 1.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/FUNDING.yml +1 -0
- data/.rubocop.yml +3 -0
- data/.rubocop_todo.yml +7 -30
- data/.yardopts +1 -0
- data/CONTRIBUTING.md +1 -1
- data/README.md +56 -31
- data/RELEASE.md +166 -0
- data/Rakefile +15 -7
- data/init.rb +1 -3
- data/lib/mocha/any_instance_method.rb +11 -53
- data/lib/mocha/api.rb +119 -56
- data/lib/mocha/block_matcher.rb +31 -0
- data/lib/mocha/cardinality.rb +52 -34
- data/lib/mocha/class_methods.rb +17 -15
- data/lib/mocha/configuration.rb +351 -67
- data/lib/mocha/deprecation.rb +2 -1
- data/lib/mocha/detection/test_unit.rb +1 -3
- data/lib/mocha/exception_raiser.rb +2 -1
- data/lib/mocha/expectation.rb +120 -81
- data/lib/mocha/expectation_error.rb +1 -3
- data/lib/mocha/expectation_list.rb +6 -6
- data/lib/mocha/inspect.rb +30 -26
- data/lib/mocha/instance_method.rb +19 -2
- data/lib/mocha/integration/mini_test.rb +7 -0
- data/lib/mocha/integration/test_unit.rb +7 -0
- data/lib/mocha/integration.rb +1 -3
- data/lib/mocha/invocation.rb +77 -0
- data/lib/mocha/macos_version.rb +5 -0
- data/lib/mocha/minitest.rb +6 -1
- data/lib/mocha/mock.rb +80 -39
- data/lib/mocha/mockery.rb +34 -80
- data/lib/mocha/names.rb +1 -1
- data/lib/mocha/object_methods.rb +13 -19
- data/lib/mocha/parameter_matchers/all_of.rb +1 -1
- data/lib/mocha/parameter_matchers/any_of.rb +1 -1
- data/lib/mocha/parameter_matchers/equivalent_uri.rb +0 -9
- data/lib/mocha/parameter_matchers/has_entries.rb +2 -3
- data/lib/mocha/parameter_matchers/has_entry.rb +24 -16
- data/lib/mocha/parameter_matchers/has_key.rb +2 -3
- data/lib/mocha/parameter_matchers/has_keys.rb +53 -0
- data/lib/mocha/parameter_matchers/has_value.rb +2 -3
- data/lib/mocha/parameter_matchers/includes.rb +2 -0
- data/lib/mocha/parameter_matchers/instance_methods.rb +18 -0
- data/lib/mocha/parameter_matchers/is_a.rb +2 -3
- data/lib/mocha/parameter_matchers/not.rb +2 -3
- data/lib/mocha/parameter_matchers.rb +2 -1
- data/lib/mocha/raised_exception.rb +11 -0
- data/lib/mocha/return_values.rb +3 -3
- data/lib/mocha/setup.rb +5 -0
- data/lib/mocha/single_return_value.rb +2 -1
- data/lib/mocha/singleton_class.rb +9 -0
- data/lib/mocha/state_machine.rb +31 -40
- data/lib/mocha/stubbed_method.rb +125 -0
- data/lib/mocha/test_unit.rb +6 -1
- data/lib/mocha/thrower.rb +2 -1
- data/lib/mocha/thrown_object.rb +12 -0
- data/lib/mocha/version.rb +1 -1
- data/lib/mocha/yield_parameters.rb +5 -11
- data/lib/mocha.rb +8 -0
- data/mocha.gemspec +14 -10
- metadata +16 -233
- data/bin/build-matrix +0 -83
- data/docs/CNAME +0 -1
- data/docs/Mocha/API.html +0 -1056
- data/docs/Mocha/ClassMethods.html +0 -267
- data/docs/Mocha/Configuration.html +0 -626
- data/docs/Mocha/Expectation.html +0 -2709
- data/docs/Mocha/ExpectationError.html +0 -157
- data/docs/Mocha/ExpectationErrorFactory.html +0 -269
- data/docs/Mocha/Hooks.html +0 -385
- data/docs/Mocha/Integration/MiniTest/Adapter.html +0 -165
- data/docs/Mocha/Integration/MiniTest.html +0 -123
- data/docs/Mocha/Integration/TestUnit/Adapter.html +0 -165
- data/docs/Mocha/Integration/TestUnit.html +0 -123
- data/docs/Mocha/Integration.html +0 -125
- data/docs/Mocha/Mock.html +0 -1197
- data/docs/Mocha/ObjectMethods.html +0 -712
- data/docs/Mocha/ParameterMatchers/AllOf.html +0 -154
- data/docs/Mocha/ParameterMatchers/AnyOf.html +0 -154
- data/docs/Mocha/ParameterMatchers/AnyParameters.html +0 -153
- data/docs/Mocha/ParameterMatchers/Anything.html +0 -153
- data/docs/Mocha/ParameterMatchers/Base.html +0 -448
- data/docs/Mocha/ParameterMatchers/Equals.html +0 -154
- data/docs/Mocha/ParameterMatchers/EquivalentUri.html +0 -153
- data/docs/Mocha/ParameterMatchers/HasEntries.html +0 -154
- data/docs/Mocha/ParameterMatchers/HasEntry.html +0 -154
- data/docs/Mocha/ParameterMatchers/HasKey.html +0 -154
- data/docs/Mocha/ParameterMatchers/HasValue.html +0 -154
- data/docs/Mocha/ParameterMatchers/Includes.html +0 -154
- data/docs/Mocha/ParameterMatchers/InstanceOf.html +0 -154
- data/docs/Mocha/ParameterMatchers/IsA.html +0 -153
- data/docs/Mocha/ParameterMatchers/KindOf.html +0 -154
- data/docs/Mocha/ParameterMatchers/Not.html +0 -154
- data/docs/Mocha/ParameterMatchers/Optionally.html +0 -153
- data/docs/Mocha/ParameterMatchers/RegexpMatches.html +0 -154
- data/docs/Mocha/ParameterMatchers/RespondsWith.html +0 -154
- data/docs/Mocha/ParameterMatchers/YamlEquivalent.html +0 -154
- data/docs/Mocha/ParameterMatchers.html +0 -3049
- data/docs/Mocha/Sequence.html +0 -149
- data/docs/Mocha/StateMachine/State.html +0 -141
- data/docs/Mocha/StateMachine/StatePredicate.html +0 -141
- data/docs/Mocha/StateMachine.html +0 -539
- data/docs/Mocha/StubbingError.html +0 -150
- data/docs/Mocha/UnexpectedInvocation.html +0 -140
- data/docs/Mocha.html +0 -127
- data/docs/_index.html +0 -537
- 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 -418
- data/docs/file.RELEASE.html +0 -875
- data/docs/file_list.html +0 -71
- data/docs/frames.html +0 -17
- data/docs/index.html +0 -418
- data/docs/js/app.js +0 -292
- data/docs/js/full_list.js +0 -216
- data/docs/js/jquery.js +0 -4
- data/docs/method_list.html +0 -571
- data/docs/top-level-namespace.html +0 -118
- 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 -113
- data/lib/mocha/mini_test.rb +0 -5
- data/lib/mocha/module_method.rb +0 -6
- data/lib/mocha/module_methods.rb +0 -10
- data/lib/mocha/multiple_yields.rb +0 -15
- data/lib/mocha/no_yields.rb +0 -5
- data/lib/mocha/parameter_matchers/object.rb +0 -15
- data/lib/mocha/pretty_parameters.rb +0 -24
- data/lib/mocha/single_yield.rb +0 -13
- data/lib/mocha/standalone.rb +0 -4
- data/lib/mocha/unexpected_invocation.rb +0 -24
- data/lib/mocha_standalone.rb +0 -4
- data/test/acceptance/acceptance_test_helper.rb +0 -35
- data/test/acceptance/bug_18914_test.rb +0 -38
- data/test/acceptance/bug_21465_test.rb +0 -32
- data/test/acceptance/bug_21563_test.rb +0 -23
- data/test/acceptance/exception_rescue_test.rb +0 -54
- data/test/acceptance/expectations_on_multiple_methods_test.rb +0 -56
- data/test/acceptance/expected_invocation_count_test.rb +0 -230
- data/test/acceptance/failure_messages_test.rb +0 -62
- data/test/acceptance/issue_272_test.rb +0 -51
- data/test/acceptance/issue_65_test.rb +0 -65
- data/test/acceptance/issue_70_test.rb +0 -54
- data/test/acceptance/mocha_example_test.rb +0 -97
- data/test/acceptance/mocha_test_result_test.rb +0 -84
- data/test/acceptance/mock_test.rb +0 -98
- data/test/acceptance/mock_with_initializer_block_test.rb +0 -56
- data/test/acceptance/mocked_methods_dispatch_test.rb +0 -76
- data/test/acceptance/multiple_expectations_failure_message_test.rb +0 -67
- data/test/acceptance/optional_parameters_test.rb +0 -68
- data/test/acceptance/parameter_matcher_test.rb +0 -300
- data/test/acceptance/partial_mocks_test.rb +0 -45
- data/test/acceptance/prepend_test.rb +0 -87
- data/test/acceptance/prevent_use_of_mocha_outside_test_test.rb +0 -77
- data/test/acceptance/raise_exception_test.rb +0 -37
- data/test/acceptance/return_value_test.rb +0 -50
- data/test/acceptance/sequence_test.rb +0 -190
- data/test/acceptance/states_test.rb +0 -72
- data/test/acceptance/stub_any_instance_method_defined_on_superclass_test.rb +0 -65
- data/test/acceptance/stub_any_instance_method_test.rb +0 -282
- 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 -79
- data/test/acceptance/stub_class_method_defined_on_module_test.rb +0 -74
- data/test/acceptance/stub_class_method_defined_on_superclass_test.rb +0 -145
- data/test/acceptance/stub_everything_test.rb +0 -54
- data/test/acceptance/stub_instance_method_defined_on_active_record_association_proxy_test.rb +0 -92
- data/test/acceptance/stub_instance_method_defined_on_class_and_aliased_test.rb +0 -68
- data/test/acceptance/stub_instance_method_defined_on_class_test.rb +0 -68
- data/test/acceptance/stub_instance_method_defined_on_kernel_module_test.rb +0 -137
- data/test/acceptance/stub_instance_method_defined_on_module_test.rb +0 -77
- data/test/acceptance/stub_instance_method_defined_on_object_class_test.rb +0 -76
- data/test/acceptance/stub_instance_method_defined_on_singleton_class_test.rb +0 -68
- data/test/acceptance/stub_instance_method_defined_on_superclass_test.rb +0 -71
- data/test/acceptance/stub_method_defined_on_module_and_aliased_test.rb +0 -39
- data/test/acceptance/stub_module_method_test.rb +0 -201
- data/test/acceptance/stub_test.rb +0 -50
- data/test/acceptance/stubba_example_test.rb +0 -94
- data/test/acceptance/stubba_test_result_test.rb +0 -72
- data/test/acceptance/stubbing_error_backtrace_test.rb +0 -64
- data/test/acceptance/stubbing_frozen_object_test.rb +0 -89
- data/test/acceptance/stubbing_method_accepting_block_parameter_test.rb +0 -53
- 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 -141
- 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 -34
- data/test/acceptance/throw_test.rb +0 -43
- data/test/acceptance/unexpected_invocation_test.rb +0 -24
- data/test/acceptance/unstubbing_test.rb +0 -195
- 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 -176
- data/test/integration/test_unit_test.rb +0 -8
- data/test/method_definer.rb +0 -22
- 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 -56
- data/test/test_unit_result.rb +0 -22
- data/test/unit/any_instance_method_test.rb +0 -150
- 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 -54
- data/test/unit/central_test.rb +0 -99
- data/test/unit/change_state_side_effect_test.rb +0 -37
- data/test/unit/class_method_test.rb +0 -254
- 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 -40
- data/test/unit/expectation_list_test.rb +0 -80
- data/test/unit/expectation_test.rb +0 -492
- 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/method_matcher_test.rb +0 -26
- data/test/unit/mock_test.rb +0 -363
- data/test/unit/mockery_test.rb +0 -174
- data/test/unit/module_methods_test.rb +0 -17
- data/test/unit/multiple_yields_test.rb +0 -16
- data/test/unit/no_yields_test.rb +0 -16
- data/test/unit/object_inspect_test.rb +0 -58
- data/test/unit/object_methods_test.rb +0 -62
- 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 -50
- 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 -61
- data/test/unit/sequence_test.rb +0 -100
- data/test/unit/single_return_value_test.rb +0 -12
- data/test/unit/single_yield_test.rb +0 -16
- 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 -18
- data/test/unit/yield_parameters_test.rb +0 -91
@@ -1,98 +0,0 @@
|
|
1
|
-
require File.expand_path('../acceptance_test_helper', __FILE__)
|
2
|
-
require 'mocha/setup'
|
3
|
-
|
4
|
-
class MockTest < 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_should_build_mock_and_explicitly_add_an_expectation_which_is_satisfied
|
16
|
-
test_result = run_as_test do
|
17
|
-
foo = mock
|
18
|
-
foo.expects(:bar)
|
19
|
-
foo.bar
|
20
|
-
end
|
21
|
-
assert_passed(test_result)
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_should_build_mock_and_explicitly_add_an_expectation_which_is_not_satisfied
|
25
|
-
test_result = run_as_test do
|
26
|
-
foo = mock
|
27
|
-
foo.expects(:bar)
|
28
|
-
end
|
29
|
-
assert_failed(test_result)
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_should_build_named_mock_and_explicitly_add_an_expectation_which_is_satisfied
|
33
|
-
test_result = run_as_test do
|
34
|
-
foo = mock('foo')
|
35
|
-
foo.expects(:bar)
|
36
|
-
foo.bar
|
37
|
-
end
|
38
|
-
assert_passed(test_result)
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_should_build_named_mock_and_explicitly_add_an_expectation_which_is_not_satisfied
|
42
|
-
test_result = run_as_test do
|
43
|
-
foo = mock('foo')
|
44
|
-
foo.expects(:bar)
|
45
|
-
end
|
46
|
-
assert_failed(test_result)
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_should_build_mock_incorporating_two_expectations_which_are_satisifed
|
50
|
-
test_result = run_as_test do
|
51
|
-
foo = mock(:bar => 'bar', :baz => 'baz')
|
52
|
-
foo.bar
|
53
|
-
foo.baz
|
54
|
-
end
|
55
|
-
assert_passed(test_result)
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_should_build_mock_incorporating_two_expectations_the_first_of_which_is_not_satisifed
|
59
|
-
test_result = run_as_test do
|
60
|
-
foo = mock(:bar => 'bar', :baz => 'baz')
|
61
|
-
foo.baz
|
62
|
-
end
|
63
|
-
assert_failed(test_result)
|
64
|
-
end
|
65
|
-
|
66
|
-
def test_should_build_mock_incorporating_two_expectations_the_second_of_which_is_not_satisifed
|
67
|
-
test_result = run_as_test do
|
68
|
-
foo = mock(:bar => 'bar', :baz => 'baz')
|
69
|
-
foo.bar
|
70
|
-
end
|
71
|
-
assert_failed(test_result)
|
72
|
-
end
|
73
|
-
|
74
|
-
def test_should_build_named_mock_incorporating_two_expectations_which_are_satisifed
|
75
|
-
test_result = run_as_test do
|
76
|
-
foo = mock('foo', :bar => 'bar', :baz => 'baz')
|
77
|
-
foo.bar
|
78
|
-
foo.baz
|
79
|
-
end
|
80
|
-
assert_passed(test_result)
|
81
|
-
end
|
82
|
-
|
83
|
-
def test_should_build_named_mock_incorporating_two_expectations_the_first_of_which_is_not_satisifed
|
84
|
-
test_result = run_as_test do
|
85
|
-
foo = mock('foo', :bar => 'bar', :baz => 'baz')
|
86
|
-
foo.baz
|
87
|
-
end
|
88
|
-
assert_failed(test_result)
|
89
|
-
end
|
90
|
-
|
91
|
-
def test_should_build_named_mock_incorporating_two_expectations_the_second_of_which_is_not_satisifed
|
92
|
-
test_result = run_as_test do
|
93
|
-
foo = mock('foo', :bar => 'bar', :baz => 'baz')
|
94
|
-
foo.bar
|
95
|
-
end
|
96
|
-
assert_failed(test_result)
|
97
|
-
end
|
98
|
-
end
|
@@ -1,56 +0,0 @@
|
|
1
|
-
require File.expand_path('../acceptance_test_helper', __FILE__)
|
2
|
-
require 'mocha/setup'
|
3
|
-
require 'deprecation_disabler'
|
4
|
-
|
5
|
-
class MockWithInitializerBlockTest < Mocha::TestCase
|
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_expect_two_method_invocations_and_receive_both_of_them
|
17
|
-
test_result = run_as_test do
|
18
|
-
DeprecationDisabler.disable_deprecations do
|
19
|
-
mock = mock() do
|
20
|
-
expects(:method_1)
|
21
|
-
expects(:method_2)
|
22
|
-
end
|
23
|
-
mock.method_1
|
24
|
-
mock.method_2
|
25
|
-
end
|
26
|
-
end
|
27
|
-
assert_passed(test_result)
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_should_expect_two_method_invocations_but_receive_only_one_of_them
|
31
|
-
test_result = run_as_test do
|
32
|
-
DeprecationDisabler.disable_deprecations do
|
33
|
-
mock = mock() do
|
34
|
-
expects(:method_1)
|
35
|
-
expects(:method_2)
|
36
|
-
end
|
37
|
-
mock.method_1
|
38
|
-
end
|
39
|
-
end
|
40
|
-
assert_failed(test_result)
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_should_stub_methods
|
44
|
-
test_result = run_as_test do
|
45
|
-
DeprecationDisabler.disable_deprecations do
|
46
|
-
mock = mock() do
|
47
|
-
stubs(:method_1).returns(1)
|
48
|
-
stubs(:method_2).returns(2)
|
49
|
-
end
|
50
|
-
assert_equal 1, mock.method_1
|
51
|
-
assert_equal 2, mock.method_2
|
52
|
-
end
|
53
|
-
end
|
54
|
-
assert_passed(test_result)
|
55
|
-
end
|
56
|
-
end
|
@@ -1,76 +0,0 @@
|
|
1
|
-
require File.expand_path('../acceptance_test_helper', __FILE__)
|
2
|
-
require 'mocha/setup'
|
3
|
-
|
4
|
-
class MockedMethodDispatchTest < 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_should_find_latest_matching_expectation
|
16
|
-
test_result = run_as_test do
|
17
|
-
mock = mock()
|
18
|
-
mock.stubs(:method).returns(1)
|
19
|
-
mock.stubs(:method).returns(2)
|
20
|
-
assert_equal 2, mock.method
|
21
|
-
assert_equal 2, mock.method
|
22
|
-
assert_equal 2, mock.method
|
23
|
-
end
|
24
|
-
assert_passed(test_result)
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_should_find_latest_expectation_which_has_not_stopped_matching
|
28
|
-
test_result = run_as_test do
|
29
|
-
mock = mock()
|
30
|
-
mock.stubs(:method).returns(1)
|
31
|
-
mock.stubs(:method).once.returns(2)
|
32
|
-
assert_equal 2, mock.method
|
33
|
-
assert_equal 1, mock.method
|
34
|
-
assert_equal 1, mock.method
|
35
|
-
end
|
36
|
-
assert_passed(test_result)
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_should_keep_finding_later_stub_and_so_never_satisfy_earlier_expectation
|
40
|
-
test_result = run_as_test do
|
41
|
-
mock = mock()
|
42
|
-
mock.expects(:method).returns(1)
|
43
|
-
mock.stubs(:method).returns(2)
|
44
|
-
assert_equal 2, mock.method
|
45
|
-
assert_equal 2, mock.method
|
46
|
-
assert_equal 2, mock.method
|
47
|
-
end
|
48
|
-
assert_failed(test_result)
|
49
|
-
end
|
50
|
-
|
51
|
-
def test_should_find_later_expectation_until_it_stops_matching_then_find_earlier_stub
|
52
|
-
test_result = run_as_test do
|
53
|
-
mock = mock()
|
54
|
-
mock.stubs(:method).returns(1)
|
55
|
-
mock.expects(:method).returns(2)
|
56
|
-
assert_equal 2, mock.method
|
57
|
-
assert_equal 1, mock.method
|
58
|
-
assert_equal 1, mock.method
|
59
|
-
end
|
60
|
-
assert_passed(test_result)
|
61
|
-
end
|
62
|
-
|
63
|
-
def test_should_find_latest_expectation_with_range_of_expected_invocation_count_which_has_not_stopped_matching
|
64
|
-
test_result = run_as_test do
|
65
|
-
mock = mock()
|
66
|
-
mock.stubs(:method).returns(1)
|
67
|
-
mock.stubs(:method).times(2..3).returns(2)
|
68
|
-
assert_equal 2, mock.method
|
69
|
-
assert_equal 2, mock.method
|
70
|
-
assert_equal 2, mock.method
|
71
|
-
assert_equal 1, mock.method
|
72
|
-
assert_equal 1, mock.method
|
73
|
-
end
|
74
|
-
assert_passed(test_result)
|
75
|
-
end
|
76
|
-
end
|
@@ -1,67 +0,0 @@
|
|
1
|
-
require File.expand_path('../acceptance_test_helper', __FILE__)
|
2
|
-
require 'mocha/setup'
|
3
|
-
|
4
|
-
class FailureMessageTest < 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_should_include_unexpected_invocation_in_unsatisfied_expectation_message
|
16
|
-
test_result = run_as_test do
|
17
|
-
mock = mock('mock')
|
18
|
-
mock.expects(:method_one).once
|
19
|
-
2.times { mock.method_one }
|
20
|
-
end
|
21
|
-
assert_failed(test_result)
|
22
|
-
assert_equal [
|
23
|
-
'unexpected invocation: #<Mock:mock>.method_one()',
|
24
|
-
'unsatisfied expectations:',
|
25
|
-
'- expected exactly once, invoked twice: #<Mock:mock>.method_one(any_parameters)'
|
26
|
-
], test_result.failure_message_lines
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_should_report_satisfied_expectations_as_well_as_unsatisfied_expectations
|
30
|
-
test_result = run_as_test do
|
31
|
-
mock = mock('mock')
|
32
|
-
mock.expects(:method_one).once
|
33
|
-
mock.expects(:method_two).twice
|
34
|
-
1.times { mock.method_one }
|
35
|
-
1.times { mock.method_two }
|
36
|
-
end
|
37
|
-
assert_failed(test_result)
|
38
|
-
assert_equal [
|
39
|
-
'not all expectations were satisfied',
|
40
|
-
'unsatisfied expectations:',
|
41
|
-
'- expected exactly twice, invoked once: #<Mock:mock>.method_two(any_parameters)',
|
42
|
-
'satisfied expectations:',
|
43
|
-
'- expected exactly once, invoked once: #<Mock:mock>.method_one(any_parameters)'
|
44
|
-
], test_result.failure_message_lines
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_should_report_multiple_satisfied_expectations
|
48
|
-
test_result = run_as_test do
|
49
|
-
mock = mock('mock')
|
50
|
-
mock.expects(:method_one).once
|
51
|
-
mock.expects(:method_two).twice
|
52
|
-
mock.expects(:method_three).times(3)
|
53
|
-
1.times { mock.method_one }
|
54
|
-
2.times { mock.method_two }
|
55
|
-
2.times { mock.method_three }
|
56
|
-
end
|
57
|
-
assert_failed(test_result)
|
58
|
-
assert_equal [
|
59
|
-
'not all expectations were satisfied',
|
60
|
-
'unsatisfied expectations:',
|
61
|
-
'- expected exactly 3 times, invoked twice: #<Mock:mock>.method_three(any_parameters)',
|
62
|
-
'satisfied expectations:',
|
63
|
-
'- expected exactly twice, invoked twice: #<Mock:mock>.method_two(any_parameters)',
|
64
|
-
'- expected exactly once, invoked once: #<Mock:mock>.method_one(any_parameters)'
|
65
|
-
], test_result.failure_message_lines
|
66
|
-
end
|
67
|
-
end
|
@@ -1,68 +0,0 @@
|
|
1
|
-
require File.expand_path('../acceptance_test_helper', __FILE__)
|
2
|
-
require 'mocha/setup'
|
3
|
-
|
4
|
-
class OptionalParameterMatcherTest < 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_should_pass_if_all_required_parameters_match_and_no_optional_parameters_are_supplied
|
16
|
-
test_result = run_as_test do
|
17
|
-
mock = mock()
|
18
|
-
mock.expects(:method).with(1, 2, optionally(3, 4))
|
19
|
-
mock.method(1, 2)
|
20
|
-
end
|
21
|
-
assert_passed(test_result)
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_should_pass_if_all_required_and_optional_parameters_match_and_some_optional_parameters_are_supplied
|
25
|
-
test_result = run_as_test do
|
26
|
-
mock = mock()
|
27
|
-
mock.expects(:method).with(1, 2, optionally(3, 4))
|
28
|
-
mock.method(1, 2, 3)
|
29
|
-
end
|
30
|
-
assert_passed(test_result)
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_should_pass_if_all_required_and_optional_parameters_match_and_all_optional_parameters_are_supplied
|
34
|
-
test_result = run_as_test do
|
35
|
-
mock = mock()
|
36
|
-
mock.expects(:method).with(1, 2, optionally(3, 4))
|
37
|
-
mock.method(1, 2, 3, 4)
|
38
|
-
end
|
39
|
-
assert_passed(test_result)
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_should_fail_if_all_required_and_optional_parameters_match_but_too_many_optional_parameters_are_supplied
|
43
|
-
test_result = run_as_test do
|
44
|
-
mock = mock()
|
45
|
-
mock.expects(:method).with(1, 2, optionally(3, 4))
|
46
|
-
mock.method(1, 2, 3, 4, 5)
|
47
|
-
end
|
48
|
-
assert_failed(test_result)
|
49
|
-
end
|
50
|
-
|
51
|
-
def test_should_fail_if_all_required_parameters_match_but_some_optional_parameters_do_not_match
|
52
|
-
test_result = run_as_test do
|
53
|
-
mock = mock()
|
54
|
-
mock.expects(:method).with(1, 2, optionally(3, 4))
|
55
|
-
mock.method(1, 2, 4)
|
56
|
-
end
|
57
|
-
assert_failed(test_result)
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_should_fail_if_all_required_parameters_match_but_no_optional_parameters_match
|
61
|
-
test_result = run_as_test do
|
62
|
-
mock = mock()
|
63
|
-
mock.expects(:method).with(1, 2, optionally(3, 4))
|
64
|
-
mock.method(1, 2, 4, 5)
|
65
|
-
end
|
66
|
-
assert_failed(test_result)
|
67
|
-
end
|
68
|
-
end
|
@@ -1,300 +0,0 @@
|
|
1
|
-
require File.expand_path('../acceptance_test_helper', __FILE__)
|
2
|
-
require 'mocha/setup'
|
3
|
-
|
4
|
-
class ParameterMatcherTest < 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_should_match_hash_parameter_with_specified_key
|
16
|
-
test_result = run_as_test do
|
17
|
-
mock = mock()
|
18
|
-
mock.expects(:method).with(has_key(:key_1))
|
19
|
-
mock.method(:key_1 => 'value_1', :key_2 => 'value_2')
|
20
|
-
end
|
21
|
-
assert_passed(test_result)
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_should_not_match_hash_parameter_with_specified_key
|
25
|
-
test_result = run_as_test do
|
26
|
-
mock = mock()
|
27
|
-
mock.expects(:method).with(has_key(:key_1))
|
28
|
-
mock.method(:key_2 => 'value_2')
|
29
|
-
end
|
30
|
-
assert_failed(test_result)
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_should_match_hash_parameter_with_specified_value
|
34
|
-
test_result = run_as_test do
|
35
|
-
mock = mock()
|
36
|
-
mock.expects(:method).with(has_value('value_1'))
|
37
|
-
mock.method(:key_1 => 'value_1', :key_2 => 'value_2')
|
38
|
-
end
|
39
|
-
assert_passed(test_result)
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_should_not_match_hash_parameter_with_specified_value
|
43
|
-
test_result = run_as_test do
|
44
|
-
mock = mock()
|
45
|
-
mock.expects(:method).with(has_value('value_1'))
|
46
|
-
mock.method(:key_2 => 'value_2')
|
47
|
-
end
|
48
|
-
assert_failed(test_result)
|
49
|
-
end
|
50
|
-
|
51
|
-
def test_should_match_hash_parameter_with_specified_key_value_pair
|
52
|
-
test_result = run_as_test do
|
53
|
-
mock = mock()
|
54
|
-
mock.expects(:method).with(has_entry(:key_1, 'value_1'))
|
55
|
-
mock.method(:key_1 => 'value_1', :key_2 => 'value_2')
|
56
|
-
end
|
57
|
-
assert_passed(test_result)
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_should_not_match_hash_parameter_with_specified_key_value_pair
|
61
|
-
test_result = run_as_test do
|
62
|
-
mock = mock()
|
63
|
-
mock.expects(:method).with(has_entry(:key_1, 'value_2'))
|
64
|
-
mock.method(:key_1 => 'value_1', :key_2 => 'value_2')
|
65
|
-
end
|
66
|
-
assert_failed(test_result)
|
67
|
-
end
|
68
|
-
|
69
|
-
def test_should_match_hash_parameter_with_specified_hash_entry
|
70
|
-
test_result = run_as_test do
|
71
|
-
mock = mock()
|
72
|
-
mock.expects(:method).with(has_entry(:key_1 => 'value_1'))
|
73
|
-
mock.method(:key_1 => 'value_1', :key_2 => 'value_2')
|
74
|
-
end
|
75
|
-
assert_passed(test_result)
|
76
|
-
end
|
77
|
-
|
78
|
-
def test_should_not_match_hash_parameter_with_specified_hash_entry
|
79
|
-
test_result = run_as_test do
|
80
|
-
mock = mock()
|
81
|
-
mock.expects(:method).with(has_entry(:key_1 => 'value_2'))
|
82
|
-
mock.method(:key_1 => 'value_1', :key_2 => 'value_2')
|
83
|
-
end
|
84
|
-
assert_failed(test_result)
|
85
|
-
end
|
86
|
-
|
87
|
-
def test_should_match_hash_parameter_with_specified_entries
|
88
|
-
test_result = run_as_test do
|
89
|
-
mock = mock()
|
90
|
-
mock.expects(:method).with(has_entries(:key_1 => 'value_1', :key_2 => 'value_2'))
|
91
|
-
mock.method(:key_1 => 'value_1', :key_2 => 'value_2', :key_3 => 'value_3')
|
92
|
-
end
|
93
|
-
assert_passed(test_result)
|
94
|
-
end
|
95
|
-
|
96
|
-
def test_should_not_match_hash_parameter_with_specified_entries
|
97
|
-
test_result = run_as_test do
|
98
|
-
mock = mock()
|
99
|
-
mock.expects(:method).with(has_entries(:key_1 => 'value_1', :key_2 => 'value_2'))
|
100
|
-
mock.method(:key_1 => 'value_1', :key_2 => 'value_3')
|
101
|
-
end
|
102
|
-
assert_failed(test_result)
|
103
|
-
end
|
104
|
-
|
105
|
-
def test_should_match_parameter_that_matches_regular_expression
|
106
|
-
test_result = run_as_test do
|
107
|
-
mock = mock()
|
108
|
-
mock.expects(:method).with(regexp_matches(/meter/))
|
109
|
-
mock.method('this parameter should match')
|
110
|
-
end
|
111
|
-
assert_passed(test_result)
|
112
|
-
end
|
113
|
-
|
114
|
-
def test_should_not_match_parameter_that_does_not_match_regular_expression
|
115
|
-
test_result = run_as_test do
|
116
|
-
mock = mock()
|
117
|
-
mock.expects(:method).with(regexp_matches(/something different/))
|
118
|
-
mock.method('this parameter should not match')
|
119
|
-
end
|
120
|
-
assert_failed(test_result)
|
121
|
-
end
|
122
|
-
|
123
|
-
def test_should_match_hash_parameter_with_specified_entries_using_nested_matchers
|
124
|
-
test_result = run_as_test do
|
125
|
-
mock = mock()
|
126
|
-
mock.expects(:method).with(has_entries(:key_1 => regexp_matches(/value_1/), kind_of(Symbol) => 'value_2'))
|
127
|
-
mock.method(:key_1 => 'value_1', :key_2 => 'value_2', :key_3 => 'value_3')
|
128
|
-
end
|
129
|
-
assert_passed(test_result)
|
130
|
-
end
|
131
|
-
|
132
|
-
def test_should_not_match_hash_parameter_with_specified_entries_using_nested_matchers
|
133
|
-
test_result = run_as_test do
|
134
|
-
mock = mock()
|
135
|
-
mock.expects(:method).with(has_entries(:key_1 => regexp_matches(/value_1/), kind_of(String) => 'value_2'))
|
136
|
-
mock.method(:key_1 => 'value_2', :key_2 => 'value_3')
|
137
|
-
end
|
138
|
-
assert_failed(test_result)
|
139
|
-
end
|
140
|
-
|
141
|
-
def test_should_match_parameter_that_matches_any_value
|
142
|
-
test_result = run_as_test do
|
143
|
-
mock = mock()
|
144
|
-
mock.expects(:method).with(any_of('value_1', 'value_2')).times(2)
|
145
|
-
mock.method('value_1')
|
146
|
-
mock.method('value_2')
|
147
|
-
end
|
148
|
-
assert_passed(test_result)
|
149
|
-
end
|
150
|
-
|
151
|
-
def test_should_not_match_parameter_that_does_not_match_any_value
|
152
|
-
test_result = run_as_test do
|
153
|
-
mock = mock()
|
154
|
-
mock.expects(:method).with(any_of('value_1', 'value_2'))
|
155
|
-
mock.method('value_3')
|
156
|
-
end
|
157
|
-
assert_failed(test_result)
|
158
|
-
end
|
159
|
-
|
160
|
-
def test_should_match_parameter_that_matches_any_of_the_given_matchers
|
161
|
-
test_result = run_as_test do
|
162
|
-
mock = mock()
|
163
|
-
mock.expects(:method).with(has_key(:foo) | has_key(:bar)).times(2)
|
164
|
-
mock.method(:foo => 'fooval')
|
165
|
-
mock.method(:bar => 'barval')
|
166
|
-
end
|
167
|
-
assert_passed(test_result)
|
168
|
-
end
|
169
|
-
|
170
|
-
def test_should_not_match_parameter_that_does_not_match_any_of_the_given_matchers
|
171
|
-
test_result = run_as_test do
|
172
|
-
mock = mock()
|
173
|
-
mock.expects(:method).with(has_key(:foo) | has_key(:bar))
|
174
|
-
mock.method(:baz => 'bazval')
|
175
|
-
end
|
176
|
-
assert_failed(test_result)
|
177
|
-
end
|
178
|
-
|
179
|
-
def test_should_match_parameter_that_matches_all_values
|
180
|
-
test_result = run_as_test do
|
181
|
-
mock = mock()
|
182
|
-
mock.expects(:method).with(all_of('value_1', 'value_1'))
|
183
|
-
mock.method('value_1')
|
184
|
-
end
|
185
|
-
assert_passed(test_result)
|
186
|
-
end
|
187
|
-
|
188
|
-
def test_should_not_match_parameter_that_does_not_match_all_values
|
189
|
-
test_result = run_as_test do
|
190
|
-
mock = mock()
|
191
|
-
mock.expects(:method).with(all_of('value_1', 'value_2'))
|
192
|
-
mock.method('value_1')
|
193
|
-
end
|
194
|
-
assert_failed(test_result)
|
195
|
-
end
|
196
|
-
|
197
|
-
def test_should_match_parameter_that_matches_all_matchers
|
198
|
-
test_result = run_as_test do
|
199
|
-
mock = mock()
|
200
|
-
mock.expects(:method).with(has_key(:foo) & has_key(:bar))
|
201
|
-
mock.method(:foo => 'fooval', :bar => 'barval')
|
202
|
-
end
|
203
|
-
assert_passed(test_result)
|
204
|
-
end
|
205
|
-
|
206
|
-
def test_should_not_match_parameter_that_does_not_match_all_matchers
|
207
|
-
test_result = run_as_test do
|
208
|
-
mock = mock()
|
209
|
-
mock.expects(:method).with(has_key(:foo) & has_key(:bar))
|
210
|
-
mock.method(:foo => 'fooval', :baz => 'bazval')
|
211
|
-
end
|
212
|
-
assert_failed(test_result)
|
213
|
-
end
|
214
|
-
|
215
|
-
def test_should_match_parameter_that_responds_with_specified_value
|
216
|
-
klass = Class.new do
|
217
|
-
def quack
|
218
|
-
'quack'
|
219
|
-
end
|
220
|
-
end
|
221
|
-
duck = klass.new
|
222
|
-
test_result = run_as_test do
|
223
|
-
mock = mock()
|
224
|
-
mock.expects(:method).with(responds_with(:quack, 'quack'))
|
225
|
-
mock.method(duck)
|
226
|
-
end
|
227
|
-
assert_passed(test_result)
|
228
|
-
end
|
229
|
-
|
230
|
-
def test_should_not_match_parameter_that_does_not_respond_with_specified_value
|
231
|
-
klass = Class.new do
|
232
|
-
def quack
|
233
|
-
'woof'
|
234
|
-
end
|
235
|
-
end
|
236
|
-
duck = klass.new
|
237
|
-
test_result = run_as_test do
|
238
|
-
mock = mock()
|
239
|
-
mock.expects(:method).with(responds_with(:quack, 'quack'))
|
240
|
-
mock.method(duck)
|
241
|
-
end
|
242
|
-
assert_failed(test_result)
|
243
|
-
end
|
244
|
-
|
245
|
-
def test_should_match_parameter_that_is_equivalent_uri
|
246
|
-
test_result = run_as_test do
|
247
|
-
mock = mock()
|
248
|
-
mock.expects(:method).with(equivalent_uri('http://example.com/foo?b=2&a=1'))
|
249
|
-
mock.method('http://example.com/foo?a=1&b=2')
|
250
|
-
end
|
251
|
-
assert_passed(test_result)
|
252
|
-
end
|
253
|
-
|
254
|
-
def test_should_not_match_parameter_that_is_not_equivalent
|
255
|
-
test_result = run_as_test do
|
256
|
-
mock = mock()
|
257
|
-
mock.expects(:method).with(equivalent_uri('http://example.com/foo?a=1'))
|
258
|
-
mock.method('http://example.com/foo?a=1&b=2')
|
259
|
-
end
|
260
|
-
assert_failed(test_result)
|
261
|
-
end
|
262
|
-
|
263
|
-
def test_should_match_parameter_when_value_is_divisible_by_four
|
264
|
-
test_result = run_as_test do
|
265
|
-
mock = mock()
|
266
|
-
mock.expects(:method).with { |actual_value| (actual_value % 4).zero? }
|
267
|
-
mock.method(8)
|
268
|
-
end
|
269
|
-
assert_passed(test_result)
|
270
|
-
end
|
271
|
-
|
272
|
-
def test_should_not_match_parameter_when_value_is_not_divisible_by_four
|
273
|
-
test_result = run_as_test do
|
274
|
-
mock = mock()
|
275
|
-
mock.expects(:method).with { |actual_value| (actual_value % 4).zero? }
|
276
|
-
mock.method(9)
|
277
|
-
end
|
278
|
-
assert_failed(test_result)
|
279
|
-
end
|
280
|
-
|
281
|
-
def test_should_match_parameters_when_values_add_up_to_ten
|
282
|
-
test_result = run_as_test do
|
283
|
-
mock = mock()
|
284
|
-
matcher = lambda { |*values| values.inject(0) { |sum, n| sum + n } == 10 }
|
285
|
-
mock.expects(:method).with(&matcher)
|
286
|
-
mock.method(1, 2, 3, 4)
|
287
|
-
end
|
288
|
-
assert_passed(test_result)
|
289
|
-
end
|
290
|
-
|
291
|
-
def test_should_not_match_parameters_when_values_do_not_add_up_to_ten
|
292
|
-
test_result = run_as_test do
|
293
|
-
mock = mock()
|
294
|
-
matcher = lambda { |*values| values.inject(0) { |sum, n| sum + n } == 10 }
|
295
|
-
mock.expects(:method).with(&matcher)
|
296
|
-
mock.method(1, 2, 3, 4, 5)
|
297
|
-
end
|
298
|
-
assert_failed(test_result)
|
299
|
-
end
|
300
|
-
end
|