mocha 1.7.0 → 1.10.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/.rubocop_todo.yml +7 -30
- data/CONTRIBUTING.md +4 -9
- data/README.md +55 -27
- data/RELEASE.md +89 -0
- data/Rakefile +15 -16
- data/bin/build-matrix +15 -2
- data/docs/CNAME +1 -0
- data/docs/Mocha.html +254 -0
- data/docs/Mocha/API.html +1287 -0
- data/docs/Mocha/ClassMethods.html +264 -0
- data/docs/Mocha/Configuration.html +1525 -0
- data/docs/Mocha/Expectation.html +2654 -0
- data/docs/Mocha/ExpectationError.html +152 -0
- data/docs/Mocha/ExpectationErrorFactory.html +260 -0
- data/docs/Mocha/Hooks.html +370 -0
- data/docs/Mocha/Integration.html +125 -0
- data/docs/Mocha/Integration/MiniTest.html +123 -0
- data/docs/Mocha/Integration/MiniTest/Adapter.html +164 -0
- data/docs/Mocha/Integration/TestUnit.html +123 -0
- data/docs/Mocha/Integration/TestUnit/Adapter.html +164 -0
- data/docs/Mocha/Mock.html +1237 -0
- data/docs/Mocha/ObjectMethods.html +765 -0
- data/docs/Mocha/ParameterMatchers.html +2961 -0
- data/docs/Mocha/ParameterMatchers/AllOf.html +153 -0
- data/docs/Mocha/ParameterMatchers/AnyOf.html +153 -0
- data/docs/Mocha/ParameterMatchers/AnyParameters.html +153 -0
- data/docs/Mocha/ParameterMatchers/Anything.html +153 -0
- data/docs/Mocha/ParameterMatchers/Base.html +441 -0
- data/docs/Mocha/ParameterMatchers/Equals.html +153 -0
- data/docs/Mocha/ParameterMatchers/EquivalentUri.html +153 -0
- data/docs/Mocha/ParameterMatchers/HasEntries.html +153 -0
- data/docs/Mocha/ParameterMatchers/HasEntry.html +153 -0
- data/docs/Mocha/ParameterMatchers/HasKey.html +153 -0
- data/docs/Mocha/ParameterMatchers/HasValue.html +153 -0
- data/docs/Mocha/ParameterMatchers/Includes.html +153 -0
- data/docs/Mocha/ParameterMatchers/InstanceOf.html +153 -0
- data/docs/Mocha/ParameterMatchers/IsA.html +153 -0
- data/docs/Mocha/ParameterMatchers/KindOf.html +153 -0
- data/docs/Mocha/ParameterMatchers/Not.html +153 -0
- data/docs/Mocha/ParameterMatchers/Optionally.html +153 -0
- data/docs/Mocha/ParameterMatchers/RegexpMatches.html +153 -0
- data/docs/Mocha/ParameterMatchers/RespondsWith.html +153 -0
- data/docs/Mocha/ParameterMatchers/YamlEquivalent.html +153 -0
- data/docs/Mocha/Sequence.html +149 -0
- data/docs/Mocha/StateMachine.html +527 -0
- data/docs/Mocha/StateMachine/State.html +140 -0
- data/docs/Mocha/StateMachine/StatePredicate.html +140 -0
- data/docs/Mocha/StubbingError.html +150 -0
- data/docs/_index.html +519 -0
- data/docs/class_list.html +51 -0
- data/docs/css/common.css +1 -0
- data/docs/css/full_list.css +58 -0
- data/docs/css/style.css +496 -0
- data/docs/file.COPYING.html +81 -0
- data/docs/file.MIT-LICENSE.html +85 -0
- data/docs/file.README.html +448 -0
- data/docs/file.RELEASE.html +974 -0
- data/docs/file_list.html +71 -0
- data/docs/frames.html +17 -0
- data/docs/index.html +448 -0
- data/docs/js/app.js +303 -0
- data/docs/js/full_list.js +216 -0
- data/docs/js/jquery.js +4 -0
- data/docs/method_list.html +635 -0
- data/docs/top-level-namespace.html +118 -0
- data/gemfiles/Gemfile.minitest.5.11.3 +7 -0
- data/init.rb +1 -3
- data/lib/mocha.rb +8 -0
- data/lib/mocha/any_instance_method.rb +11 -53
- data/lib/mocha/api.rb +120 -56
- data/lib/mocha/cardinality.rb +26 -11
- 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 +56 -58
- data/lib/mocha/expectation_error.rb +1 -3
- data/lib/mocha/expectation_list.rb +6 -6
- data/lib/mocha/inspect.rb +28 -26
- data/lib/mocha/instance_method.rb +19 -2
- data/lib/mocha/integration.rb +1 -3
- data/lib/mocha/integration/mini_test.rb +7 -0
- data/lib/mocha/integration/test_unit.rb +7 -0
- data/lib/mocha/invocation.rb +73 -0
- data/lib/mocha/macos_version.rb +5 -0
- data/lib/mocha/minitest.rb +6 -1
- data/lib/mocha/mock.rb +46 -31
- data/lib/mocha/mockery.rb +25 -61
- data/lib/mocha/names.rb +1 -1
- data/lib/mocha/object_methods.rb +13 -19
- data/lib/mocha/parameter_matchers.rb +1 -1
- 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/includes.rb +2 -0
- data/lib/mocha/parameter_matchers/instance_methods.rb +18 -0
- 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/stubbed_method.rb +127 -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/mocha.gemspec +3 -6
- data/test/acceptance/acceptance_test_helper.rb +6 -0
- data/test/acceptance/bug_18914_test.rb +0 -1
- data/test/acceptance/bug_21465_test.rb +0 -1
- data/test/acceptance/bug_21563_test.rb +0 -1
- data/test/acceptance/display_matching_invocations_alongside_expectations_test.rb +69 -0
- data/test/acceptance/exception_rescue_test.rb +1 -2
- data/test/acceptance/expectations_on_multiple_methods_test.rb +0 -1
- data/test/acceptance/expected_invocation_count_test.rb +2 -3
- data/test/acceptance/failure_messages_test.rb +0 -1
- data/test/acceptance/issue_272_test.rb +1 -2
- data/test/acceptance/issue_65_test.rb +0 -1
- data/test/acceptance/issue_70_test.rb +0 -1
- data/test/acceptance/mocha_example_test.rb +0 -1
- data/test/acceptance/mocha_test_result_test.rb +0 -1
- data/test/acceptance/mock_built_with_first_argument_type_being_string_test.rb +99 -0
- data/test/acceptance/mock_test.rb +47 -6
- data/test/acceptance/mocked_methods_dispatch_test.rb +0 -1
- data/test/acceptance/multiple_expectations_failure_message_test.rb +0 -1
- data/test/acceptance/optional_parameters_test.rb +0 -1
- data/test/acceptance/parameter_matcher_test.rb +0 -1
- data/test/acceptance/partial_mocks_test.rb +0 -1
- data/test/acceptance/prepend_test.rb +0 -1
- data/test/acceptance/prevent_use_of_mocha_outside_test_test.rb +0 -1
- data/test/acceptance/raise_exception_test.rb +0 -1
- data/test/acceptance/return_value_test.rb +0 -1
- data/test/acceptance/sequence_test.rb +0 -1
- data/test/acceptance/states_test.rb +0 -1
- data/test/acceptance/stub_any_instance_method_defined_on_superclass_test.rb +1 -2
- data/test/acceptance/stub_any_instance_method_test.rb +20 -1
- data/test/acceptance/stub_class_method_defined_on_active_record_association_proxy_test.rb +0 -1
- data/test/acceptance/stub_class_method_defined_on_class_test.rb +0 -1
- data/test/acceptance/stub_class_method_defined_on_module_test.rb +0 -1
- data/test/acceptance/stub_class_method_defined_on_superclass_test.rb +1 -2
- data/test/acceptance/stub_everything_test.rb +0 -1
- data/test/acceptance/stub_instance_method_defined_on_active_record_association_proxy_test.rb +0 -1
- data/test/acceptance/stub_instance_method_defined_on_class_and_aliased_test.rb +0 -1
- data/test/acceptance/stub_instance_method_defined_on_class_test.rb +0 -1
- data/test/acceptance/stub_instance_method_defined_on_kernel_module_test.rb +0 -1
- data/test/acceptance/stub_instance_method_defined_on_module_test.rb +0 -1
- data/test/acceptance/stub_instance_method_defined_on_object_class_test.rb +0 -1
- data/test/acceptance/stub_instance_method_defined_on_singleton_class_test.rb +0 -1
- data/test/acceptance/stub_instance_method_defined_on_superclass_test.rb +0 -1
- data/test/acceptance/stub_method_defined_on_module_and_aliased_test.rb +0 -1
- data/test/acceptance/stub_module_method_test.rb +0 -1
- data/test/acceptance/stub_test.rb +0 -1
- data/test/acceptance/stubba_example_test.rb +0 -1
- data/test/acceptance/stubba_test_result_test.rb +0 -1
- data/test/acceptance/stubbing_error_backtrace_test.rb +4 -5
- data/test/acceptance/stubbing_frozen_object_test.rb +0 -1
- data/test/acceptance/stubbing_method_accepting_block_parameter_test.rb +0 -1
- data/test/acceptance/stubbing_method_unnecessarily_test.rb +5 -5
- data/test/acceptance/stubbing_nil_test.rb +5 -5
- data/test/acceptance/stubbing_non_existent_any_instance_method_test.rb +27 -11
- data/test/acceptance/stubbing_non_existent_class_method_test.rb +11 -11
- data/test/acceptance/stubbing_non_existent_instance_method_test.rb +11 -11
- data/test/acceptance/stubbing_non_public_any_instance_method_test.rb +8 -8
- data/test/acceptance/stubbing_non_public_class_method_test.rb +9 -9
- data/test/acceptance/stubbing_non_public_instance_method_test.rb +9 -9
- data/test/acceptance/stubbing_on_non_mock_object_test.rb +5 -5
- data/test/acceptance/stubbing_same_class_method_on_parent_and_child_classes_test.rb +0 -1
- data/test/acceptance/throw_test.rb +0 -1
- data/test/acceptance/unexpected_invocation_test.rb +0 -1
- data/test/acceptance/unstubbing_test.rb +0 -1
- data/test/integration/shared_tests.rb +5 -3
- data/test/method_definer.rb +11 -17
- data/test/test_runner.rb +2 -0
- data/test/unit/any_instance_method_test.rb +60 -35
- data/test/unit/cardinality_test.rb +41 -23
- data/test/unit/central_test.rb +0 -1
- data/test/unit/class_methods_test.rb +1 -1
- data/test/unit/configuration_test.rb +12 -12
- data/test/unit/exception_raiser_test.rb +10 -5
- data/test/unit/expectation_list_test.rb +13 -11
- data/test/unit/expectation_test.rb +103 -103
- data/test/unit/instance_method_test.rb +282 -0
- data/test/unit/mock_test.rb +28 -19
- data/test/unit/mockery_test.rb +8 -11
- data/test/unit/module_methods_test.rb +2 -3
- data/test/unit/object_inspect_test.rb +16 -4
- data/test/unit/object_methods_test.rb +3 -2
- data/test/unit/parameter_matchers/equivalent_uri_test.rb +0 -9
- data/test/unit/parameter_matchers/has_entries_test.rb +1 -1
- data/test/unit/parameter_matchers/has_entry_test.rb +1 -1
- data/test/unit/parameter_matchers/has_key_test.rb +1 -1
- data/test/unit/parameter_matchers/has_value_test.rb +1 -1
- data/test/unit/parameter_matchers/includes_test.rb +1 -1
- data/test/unit/parameter_matchers/responds_with_test.rb +1 -1
- data/test/unit/return_values_test.rb +25 -20
- data/test/unit/single_return_value_test.rb +6 -1
- data/test/unit/thrower_test.rb +7 -2
- data/yard-templates/default/layout/html/google_analytics.erb +6 -9
- metadata +78 -61
- 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/parameter_matchers/object.rb +0 -15
- 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/mock_with_initializer_block_test.rb +0 -56
- data/test/unit/class_method_test.rb +0 -254
@@ -1,43 +1,61 @@
|
|
1
1
|
require File.expand_path('../../test_helper', __FILE__)
|
2
2
|
require 'mocha/cardinality'
|
3
|
+
require 'mocha/invocation'
|
4
|
+
require 'mocha/return_values'
|
5
|
+
require 'mocha/yield_parameters'
|
3
6
|
|
4
7
|
class CardinalityTest < Mocha::TestCase
|
5
8
|
include Mocha
|
6
9
|
|
10
|
+
def new_invocation
|
11
|
+
Invocation.new(:irrelevant, :irrelevant)
|
12
|
+
end
|
13
|
+
|
7
14
|
def test_should_allow_invocations_if_invocation_count_has_not_yet_reached_maximum
|
8
15
|
cardinality = Cardinality.new(2, 3)
|
9
|
-
assert cardinality.invocations_allowed?
|
10
|
-
|
11
|
-
assert cardinality.invocations_allowed?
|
12
|
-
|
16
|
+
assert cardinality.invocations_allowed?
|
17
|
+
cardinality << new_invocation
|
18
|
+
assert cardinality.invocations_allowed?
|
19
|
+
cardinality << new_invocation
|
20
|
+
assert cardinality.invocations_allowed?
|
21
|
+
cardinality << new_invocation
|
22
|
+
assert !cardinality.invocations_allowed?
|
13
23
|
end
|
14
24
|
|
15
25
|
def test_should_be_satisfied_if_invocations_so_far_have_reached_required_threshold
|
16
26
|
cardinality = Cardinality.new(2, 3)
|
17
|
-
assert !cardinality.satisfied?
|
18
|
-
|
19
|
-
assert cardinality.satisfied?
|
20
|
-
|
27
|
+
assert !cardinality.satisfied?
|
28
|
+
cardinality << new_invocation
|
29
|
+
assert !cardinality.satisfied?
|
30
|
+
cardinality << new_invocation
|
31
|
+
assert cardinality.satisfied?
|
32
|
+
cardinality << new_invocation
|
33
|
+
assert cardinality.satisfied?
|
21
34
|
end
|
22
35
|
|
23
|
-
def
|
24
|
-
assert_equal 'allowed any number of times', Cardinality.at_least(0).
|
25
|
-
|
26
|
-
assert_equal 'expected at
|
27
|
-
assert_equal 'expected at
|
28
|
-
|
36
|
+
def test_should_describe_cardinality_defined_using_at_least
|
37
|
+
assert_equal 'allowed any number of times', Cardinality.at_least(0).anticipated_times
|
38
|
+
assert_equal 'expected at least once', Cardinality.at_least(1).anticipated_times
|
39
|
+
assert_equal 'expected at least twice', Cardinality.at_least(2).anticipated_times
|
40
|
+
assert_equal 'expected at least 3 times', Cardinality.at_least(3).anticipated_times
|
41
|
+
end
|
29
42
|
|
30
|
-
|
31
|
-
assert_equal 'expected at
|
32
|
-
assert_equal 'expected at
|
43
|
+
def test_should_describe_cardinality_defined_using_at_most
|
44
|
+
assert_equal 'expected at most once', Cardinality.at_most(1).anticipated_times
|
45
|
+
assert_equal 'expected at most twice', Cardinality.at_most(2).anticipated_times
|
46
|
+
assert_equal 'expected at most 3 times', Cardinality.at_most(3).anticipated_times
|
47
|
+
end
|
33
48
|
|
34
|
-
|
35
|
-
assert_equal 'expected
|
36
|
-
assert_equal 'expected exactly
|
37
|
-
assert_equal 'expected exactly
|
49
|
+
def test_should_describe_cardinality_defined_using_exactly
|
50
|
+
assert_equal 'expected never', Cardinality.exactly(0).anticipated_times
|
51
|
+
assert_equal 'expected exactly once', Cardinality.exactly(1).anticipated_times
|
52
|
+
assert_equal 'expected exactly twice', Cardinality.exactly(2).anticipated_times
|
53
|
+
assert_equal 'expected exactly 3 times', Cardinality.exactly(3).anticipated_times
|
54
|
+
end
|
38
55
|
|
39
|
-
|
40
|
-
assert_equal 'expected between
|
56
|
+
def test_should_describe_cardinality_defined_using_times_with_range
|
57
|
+
assert_equal 'expected between 2 and 4 times', Cardinality.times(2..4).anticipated_times
|
58
|
+
assert_equal 'expected between 1 and 3 times', Cardinality.times(1..3).anticipated_times
|
41
59
|
end
|
42
60
|
|
43
61
|
def test_should_need_verifying
|
data/test/unit/central_test.rb
CHANGED
@@ -51,7 +51,7 @@ class ClassMethodsTest < Mocha::TestCase
|
|
51
51
|
end
|
52
52
|
|
53
53
|
def test_should_use_stubba_class_method_for_class
|
54
|
-
assert_equal Mocha::
|
54
|
+
assert_equal Mocha::InstanceMethod, @klass.stubba_method
|
55
55
|
end
|
56
56
|
|
57
57
|
def test_should_use_stubba_class_method_for_any_instance
|
@@ -3,35 +3,35 @@ require 'mocha/configuration'
|
|
3
3
|
|
4
4
|
class ConfigurationTest < Mocha::TestCase
|
5
5
|
def test_allow_temporarily_changes_config_when_given_block
|
6
|
-
Mocha
|
6
|
+
Mocha.configure { |c| c.stubbing_method_unnecessarily = :warn }
|
7
7
|
yielded = false
|
8
|
-
Mocha::Configuration.
|
8
|
+
Mocha::Configuration.override(:stubbing_method_unnecessarily => :allow) do
|
9
9
|
yielded = true
|
10
|
-
|
10
|
+
assert_equal :allow, Mocha.configuration.stubbing_method_unnecessarily
|
11
11
|
end
|
12
12
|
assert yielded
|
13
|
-
|
13
|
+
assert_equal :warn, Mocha.configuration.stubbing_method_unnecessarily
|
14
14
|
end
|
15
15
|
|
16
16
|
def test_prevent_temporarily_changes_config_when_given_block
|
17
|
-
Mocha
|
17
|
+
Mocha.configure { |c| c.stubbing_method_unnecessarily = :allow }
|
18
18
|
yielded = false
|
19
|
-
Mocha::Configuration.
|
19
|
+
Mocha::Configuration.override(:stubbing_method_unnecessarily => :prevent) do
|
20
20
|
yielded = true
|
21
|
-
|
21
|
+
assert_equal :prevent, Mocha.configuration.stubbing_method_unnecessarily
|
22
22
|
end
|
23
23
|
assert yielded
|
24
|
-
|
24
|
+
assert_equal :allow, Mocha.configuration.stubbing_method_unnecessarily
|
25
25
|
end
|
26
26
|
|
27
27
|
def test_warn_when_temporarily_changes_config_when_given_block
|
28
|
-
Mocha
|
28
|
+
Mocha.configure { |c| c.stubbing_method_unnecessarily = :allow }
|
29
29
|
yielded = false
|
30
|
-
Mocha::Configuration.
|
30
|
+
Mocha::Configuration.override(:stubbing_method_unnecessarily => :warn) do
|
31
31
|
yielded = true
|
32
|
-
|
32
|
+
assert_equal :warn, Mocha.configuration.stubbing_method_unnecessarily
|
33
33
|
end
|
34
34
|
assert yielded
|
35
|
-
|
35
|
+
assert_equal :allow, Mocha.configuration.stubbing_method_unnecessarily
|
36
36
|
end
|
37
37
|
end
|
@@ -1,40 +1,45 @@
|
|
1
1
|
require File.expand_path('../../test_helper', __FILE__)
|
2
2
|
|
3
|
+
require 'mocha/invocation'
|
3
4
|
require 'mocha/exception_raiser'
|
4
5
|
require 'timeout'
|
5
6
|
|
6
7
|
class ExceptionRaiserTest < Mocha::TestCase
|
7
8
|
include Mocha
|
8
9
|
|
10
|
+
def new_invocation
|
11
|
+
Invocation.new(:irrelevant, :irrelevant)
|
12
|
+
end
|
13
|
+
|
9
14
|
def test_should_raise_exception_with_specified_class_and_default_message
|
10
15
|
exception_class = Class.new(StandardError)
|
11
16
|
raiser = ExceptionRaiser.new(exception_class, nil)
|
12
|
-
exception = assert_raises(exception_class) { raiser.evaluate }
|
17
|
+
exception = assert_raises(exception_class) { raiser.evaluate(new_invocation) }
|
13
18
|
assert_equal exception_class.to_s, exception.message
|
14
19
|
end
|
15
20
|
|
16
21
|
def test_should_raise_exception_with_specified_class_and_message
|
17
22
|
exception_class = Class.new(StandardError)
|
18
23
|
raiser = ExceptionRaiser.new(exception_class, 'message')
|
19
|
-
exception = assert_raises(exception_class) { raiser.evaluate }
|
24
|
+
exception = assert_raises(exception_class) { raiser.evaluate(new_invocation) }
|
20
25
|
assert_equal 'message', exception.message
|
21
26
|
end
|
22
27
|
|
23
28
|
def test_should_raise_exception_instance
|
24
29
|
exception_class = Class.new(StandardError)
|
25
30
|
raiser = ExceptionRaiser.new(exception_class.new('message'), nil)
|
26
|
-
exception = assert_raises(exception_class) { raiser.evaluate }
|
31
|
+
exception = assert_raises(exception_class) { raiser.evaluate(new_invocation) }
|
27
32
|
assert_equal 'message', exception.message
|
28
33
|
end
|
29
34
|
|
30
35
|
def test_should_raise_interrupt_exception_with_default_message_so_it_works_in_ruby_1_8_6
|
31
36
|
raiser = ExceptionRaiser.new(Interrupt, nil)
|
32
|
-
assert_raises(Interrupt) { raiser.evaluate }
|
37
|
+
assert_raises(Interrupt) { raiser.evaluate(new_invocation) }
|
33
38
|
end
|
34
39
|
|
35
40
|
def test_should_raise_subclass_of_interrupt_exception_with_default_message_so_it_works_in_ruby_1_8_6
|
36
41
|
exception_class = Class.new(Interrupt)
|
37
42
|
raiser = ExceptionRaiser.new(exception_class, nil)
|
38
|
-
assert_raises(exception_class) { raiser.evaluate }
|
43
|
+
assert_raises(exception_class) { raiser.evaluate(new_invocation) }
|
39
44
|
end
|
40
45
|
end
|
@@ -1,10 +1,12 @@
|
|
1
1
|
require File.expand_path('../../test_helper', __FILE__)
|
2
2
|
require 'mocha/expectation_list'
|
3
3
|
require 'mocha/expectation'
|
4
|
+
require 'mocha/invocation'
|
4
5
|
require 'set'
|
5
6
|
require 'method_definer'
|
6
7
|
|
7
8
|
class ExpectationListTest < Mocha::TestCase
|
9
|
+
include MethodDefiner
|
8
10
|
include Mocha
|
9
11
|
|
10
12
|
def test_should_return_added_expectation
|
@@ -19,7 +21,7 @@ class ExpectationListTest < Mocha::TestCase
|
|
19
21
|
expectation2 = Expectation.new(nil, :my_method).with(:argument3, :argument4)
|
20
22
|
expectation_list.add(expectation1)
|
21
23
|
expectation_list.add(expectation2)
|
22
|
-
assert_same expectation1, expectation_list.match(:my_method, :argument1, :argument2)
|
24
|
+
assert_same expectation1, expectation_list.match(Invocation.new(:irrelevant, :my_method, :argument1, :argument2))
|
23
25
|
end
|
24
26
|
|
25
27
|
def test_should_remove_all_expectations_matching_method_name
|
@@ -31,9 +33,9 @@ class ExpectationListTest < Mocha::TestCase
|
|
31
33
|
expectation_list.add(expectation2)
|
32
34
|
expectation_list.add(expectation3)
|
33
35
|
expectation_list.remove_all_matching_method(:method_one)
|
34
|
-
assert_nil expectation_list.match(:method_one, :argument1, :argument2)
|
35
|
-
assert_nil expectation_list.match(:method_one, :argument3, :argument4)
|
36
|
-
assert_same expectation3, expectation_list.match(:method_two)
|
36
|
+
assert_nil expectation_list.match(Invocation.new(:irrelevant, :method_one, :argument1, :argument2))
|
37
|
+
assert_nil expectation_list.match(Invocation.new(:irrelevant, :method_one, :argument3, :argument4))
|
38
|
+
assert_same expectation3, expectation_list.match(Invocation.new(:irrelevant, :method_two))
|
37
39
|
end
|
38
40
|
|
39
41
|
def test_should_find_most_recent_matching_expectation
|
@@ -42,29 +44,29 @@ class ExpectationListTest < Mocha::TestCase
|
|
42
44
|
expectation2 = Expectation.new(nil, :my_method).with(:argument1, :argument2)
|
43
45
|
expectation_list.add(expectation1)
|
44
46
|
expectation_list.add(expectation2)
|
45
|
-
assert_same expectation2, expectation_list.match(:my_method, :argument1, :argument2)
|
47
|
+
assert_same expectation2, expectation_list.match(Invocation.new(:irrelevant, :my_method, :argument1, :argument2))
|
46
48
|
end
|
47
49
|
|
48
50
|
def test_should_find_matching_expectation_allowing_invocation
|
49
51
|
expectation_list = ExpectationList.new
|
50
52
|
expectation1 = Expectation.new(nil, :my_method).with(:argument1, :argument2)
|
51
53
|
expectation2 = Expectation.new(nil, :my_method).with(:argument3, :argument4)
|
52
|
-
|
53
|
-
|
54
|
+
define_instance_method(expectation1, :invocations_allowed?) { true }
|
55
|
+
define_instance_method(expectation2, :invocations_allowed?) { true }
|
54
56
|
expectation_list.add(expectation1)
|
55
57
|
expectation_list.add(expectation2)
|
56
|
-
assert_same expectation1, expectation_list.match_allowing_invocation(:my_method, :argument1, :argument2)
|
58
|
+
assert_same expectation1, expectation_list.match_allowing_invocation(Invocation.new(:irrelevant, :my_method, :argument1, :argument2))
|
57
59
|
end
|
58
60
|
|
59
61
|
def test_should_find_most_recent_matching_expectation_allowing_invocation
|
60
62
|
expectation_list = ExpectationList.new
|
61
63
|
expectation1 = Expectation.new(nil, :my_method)
|
62
64
|
expectation2 = Expectation.new(nil, :my_method)
|
63
|
-
|
64
|
-
|
65
|
+
define_instance_method(expectation1, :invocations_allowed?) { true }
|
66
|
+
define_instance_method(expectation2, :invocations_allowed?) { false }
|
65
67
|
expectation_list.add(expectation1)
|
66
68
|
expectation_list.add(expectation2)
|
67
|
-
assert_same expectation1, expectation_list.match_allowing_invocation(:my_method)
|
69
|
+
assert_same expectation1, expectation_list.match_allowing_invocation(Invocation.new(:irrelevant, :my_method))
|
68
70
|
end
|
69
71
|
|
70
72
|
def test_should_combine_two_expectation_lists_into_one
|
@@ -1,9 +1,12 @@
|
|
1
1
|
require File.expand_path('../../test_helper', __FILE__)
|
2
|
-
require 'method_definer'
|
3
2
|
require 'mocha/expectation'
|
3
|
+
require 'mocha/invocation'
|
4
4
|
require 'mocha/sequence'
|
5
|
+
require 'mocha/configuration'
|
6
|
+
require 'mocha/deprecation'
|
5
7
|
require 'execution_point'
|
6
8
|
require 'simple_counter'
|
9
|
+
require 'deprecation_disabler'
|
7
10
|
|
8
11
|
class ExpectationTest < Mocha::TestCase
|
9
12
|
include Mocha
|
@@ -12,90 +15,85 @@ class ExpectationTest < Mocha::TestCase
|
|
12
15
|
Expectation.new(nil, :expected_method)
|
13
16
|
end
|
14
17
|
|
18
|
+
def invoke(expectation, &block)
|
19
|
+
expectation.invoke(Invocation.new(:irrelevant, :expected_method, &block))
|
20
|
+
end
|
21
|
+
|
15
22
|
def test_should_match_calls_to_same_method_with_any_parameters
|
16
|
-
assert new_expectation.match?(:expected_method, 1, 2, 3)
|
23
|
+
assert new_expectation.match?(Invocation.new(:irrelevant, :expected_method, 1, 2, 3))
|
17
24
|
end
|
18
25
|
|
19
26
|
def test_should_match_calls_to_same_method_with_exactly_zero_parameters
|
20
|
-
|
21
|
-
assert expectation.match?(:expected_method)
|
27
|
+
assert new_expectation.with.match?(Invocation.new(:irrelevant, :expected_method))
|
22
28
|
end
|
23
29
|
|
24
30
|
def test_should_not_match_calls_to_same_method_with_more_than_zero_parameters
|
25
|
-
|
26
|
-
assert !expectation.match?(:expected_method, 1, 2, 3)
|
31
|
+
assert !new_expectation.with.match?(Invocation.new(:irrelevant, :expected_method, 1, 2, 3))
|
27
32
|
end
|
28
33
|
|
29
34
|
def test_should_match_calls_to_same_method_with_expected_parameter_values
|
30
|
-
|
31
|
-
assert expectation.match?(:expected_method, 1, 2, 3)
|
35
|
+
assert new_expectation.with(1, 2, 3).match?(Invocation.new(:irrelevant, :expected_method, 1, 2, 3))
|
32
36
|
end
|
33
37
|
|
34
38
|
def test_should_match_calls_to_same_method_with_parameters_constrained_as_expected
|
35
39
|
expectation = new_expectation.with { |x, y, z| x + y == z }
|
36
|
-
assert expectation.match?(:expected_method, 1, 2, 3)
|
40
|
+
assert expectation.match?(Invocation.new(:irrelevant, :expected_method, 1, 2, 3))
|
37
41
|
end
|
38
42
|
|
39
43
|
def test_should_not_match_calls_to_different_method_with_parameters_constrained_as_expected
|
40
44
|
expectation = new_expectation.with { |x, y, z| x + y == z }
|
41
|
-
assert !expectation.match?(:different_method, 1, 2, 3)
|
45
|
+
assert !expectation.match?(Invocation.new(:irrelevant, :different_method, 1, 2, 3))
|
42
46
|
end
|
43
47
|
|
44
48
|
def test_should_not_match_calls_to_different_methods_with_no_parameters
|
45
|
-
assert !new_expectation.match?(:unexpected_method)
|
49
|
+
assert !new_expectation.match?(Invocation.new(:irrelevant, :unexpected_method))
|
46
50
|
end
|
47
51
|
|
48
52
|
def test_should_not_match_calls_to_same_method_with_too_few_parameters
|
49
|
-
|
50
|
-
assert !expectation.match?(:unexpected_method, 1, 2)
|
53
|
+
assert !new_expectation.with(1, 2, 3).match?(Invocation.new(:irrelevant, :expected_method, 1, 2))
|
51
54
|
end
|
52
55
|
|
53
56
|
def test_should_not_match_calls_to_same_method_with_too_many_parameters
|
54
|
-
|
55
|
-
assert !expectation.match?(:unexpected_method, 1, 2, 3)
|
57
|
+
assert !new_expectation.with(1, 2).match?(Invocation.new(:irrelevant, :expected_method, 1, 2, 3))
|
56
58
|
end
|
57
59
|
|
58
60
|
def test_should_not_match_calls_to_same_method_with_unexpected_parameter_values
|
59
|
-
|
60
|
-
assert !expectation.match?(:unexpected_method, 1, 0, 3)
|
61
|
+
assert !new_expectation.with(1, 2, 3).match?(Invocation.new(:irrelevant, :expected_method, 1, 0, 3))
|
61
62
|
end
|
62
63
|
|
63
64
|
def test_should_not_match_calls_to_same_method_with_parameters_not_constrained_as_expected
|
64
65
|
expectation = new_expectation.with { |x, y, z| x + y == z }
|
65
|
-
assert !expectation.match?(:expected_method, 1, 0, 3)
|
66
|
+
assert !expectation.match?(Invocation.new(:irrelevant, :expected_method, 1, 0, 3))
|
66
67
|
end
|
67
68
|
|
68
69
|
def test_should_allow_invocations_until_expected_invocation_count_is_one_and_actual_invocation_count_would_be_two
|
69
70
|
expectation = new_expectation.times(1)
|
70
71
|
assert expectation.invocations_allowed?
|
71
|
-
expectation
|
72
|
+
invoke(expectation)
|
72
73
|
assert !expectation.invocations_allowed?
|
73
74
|
end
|
74
75
|
|
75
76
|
def test_should_allow_invocations_until_expected_invocation_count_is_two_and_actual_invocation_count_would_be_three
|
76
77
|
expectation = new_expectation.times(2)
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
78
|
+
2.times do
|
79
|
+
assert expectation.invocations_allowed?
|
80
|
+
invoke(expectation)
|
81
|
+
end
|
81
82
|
assert !expectation.invocations_allowed?
|
82
83
|
end
|
83
84
|
|
84
85
|
def test_should_allow_invocations_until_expected_invocation_count_is_a_range_from_two_to_three_and_actual_invocation_count_would_be_four
|
85
86
|
expectation = new_expectation.times(2..3)
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
assert expectation.invocations_allowed?
|
91
|
-
expectation.invoke
|
87
|
+
3.times do
|
88
|
+
assert expectation.invocations_allowed?
|
89
|
+
invoke(expectation)
|
90
|
+
end
|
92
91
|
assert !expectation.invocations_allowed?
|
93
92
|
end
|
94
93
|
|
95
94
|
def test_should_store_provided_backtrace
|
96
95
|
backtrace = Object.new
|
97
|
-
|
98
|
-
assert_equal backtrace, expectation.backtrace
|
96
|
+
assert_equal backtrace, Expectation.new(nil, :expected_method, backtrace).backtrace
|
99
97
|
end
|
100
98
|
|
101
99
|
# rubocop:disable Style/Semicolon
|
@@ -107,217 +105,221 @@ class ExpectationTest < Mocha::TestCase
|
|
107
105
|
|
108
106
|
def test_should_not_yield
|
109
107
|
yielded = false
|
110
|
-
new_expectation
|
108
|
+
invoke(new_expectation) { yielded = true }
|
111
109
|
assert_equal false, yielded
|
112
110
|
end
|
113
111
|
|
114
112
|
def test_should_yield_no_parameters
|
115
|
-
expectation = new_expectation.yields
|
116
113
|
yielded_parameters = nil
|
117
|
-
|
114
|
+
invoke(new_expectation.yields) { |*parameters| yielded_parameters = parameters }
|
118
115
|
assert_equal [], yielded_parameters
|
119
116
|
end
|
120
117
|
|
118
|
+
def test_yield_should_fail_when_the_caller_does_not_provide_a_block
|
119
|
+
assert_raises(LocalJumpError) { invoke(new_expectation.yields(:foo)) }
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_yield_should_display_warning_when_caller_does_not_provide_block_and_behaviour_from_v1_9_retained
|
123
|
+
Mocha::Configuration.override(:reinstate_undocumented_behaviour_from_v1_9 => true) do
|
124
|
+
DeprecationDisabler.disable_deprecations do
|
125
|
+
invoke(new_expectation.yields(:foo, 1, [2, 3]))
|
126
|
+
end
|
127
|
+
end
|
128
|
+
assert message = Deprecation.messages.last
|
129
|
+
assert message.include?('Stubbed method was instructed to yield (:foo, 1, [2, 3])')
|
130
|
+
assert message.include?('but no block was given by invocation: :irrelevant.expected_method()')
|
131
|
+
assert message.include?('This will raise a LocalJumpError in the future.')
|
132
|
+
end
|
133
|
+
|
121
134
|
def test_should_yield_with_specified_parameters
|
122
|
-
expectation = new_expectation.yields(1, 2, 3)
|
123
135
|
yielded_parameters = nil
|
124
|
-
|
136
|
+
invoke(new_expectation.yields(1, 2, 3)) { |*parameters| yielded_parameters = parameters }
|
125
137
|
assert_equal [1, 2, 3], yielded_parameters
|
126
138
|
end
|
127
139
|
|
128
140
|
def test_should_yield_different_parameters_on_consecutive_invocations
|
129
141
|
expectation = new_expectation.yields(1, 2, 3).yields(4, 5)
|
130
142
|
yielded_parameters = []
|
131
|
-
expectation
|
132
|
-
expectation
|
143
|
+
invoke(expectation) { |*parameters| yielded_parameters << parameters }
|
144
|
+
invoke(expectation) { |*parameters| yielded_parameters << parameters }
|
133
145
|
assert_equal [[1, 2, 3], [4, 5]], yielded_parameters
|
134
146
|
end
|
135
147
|
|
136
148
|
def test_should_yield_multiple_times_for_single_invocation
|
137
|
-
expectation = new_expectation.multiple_yields([1, 2, 3], [4, 5])
|
138
149
|
yielded_parameters = []
|
139
|
-
|
150
|
+
invoke(new_expectation.multiple_yields([1, 2, 3], [4, 5])) { |*parameters| yielded_parameters << parameters }
|
140
151
|
assert_equal [[1, 2, 3], [4, 5]], yielded_parameters
|
141
152
|
end
|
142
153
|
|
143
154
|
def test_should_yield_multiple_times_for_first_invocation_and_once_for_second_invocation
|
144
155
|
expectation = new_expectation.multiple_yields([1, 2, 3], [4, 5]).then.yields(6, 7)
|
145
156
|
yielded_parameters = []
|
146
|
-
expectation
|
147
|
-
expectation
|
157
|
+
invoke(expectation) { |*parameters| yielded_parameters << parameters }
|
158
|
+
invoke(expectation) { |*parameters| yielded_parameters << parameters }
|
148
159
|
assert_equal [[1, 2, 3], [4, 5], [6, 7]], yielded_parameters
|
149
160
|
end
|
150
161
|
|
151
162
|
def test_should_return_specified_value
|
152
|
-
|
153
|
-
assert_equal 99, expectation.invoke
|
163
|
+
assert_equal 99, invoke(new_expectation.returns(99))
|
154
164
|
end
|
155
165
|
|
156
166
|
def test_should_return_same_specified_value_multiple_times
|
157
167
|
expectation = new_expectation.returns(99)
|
158
|
-
assert_equal 99, expectation
|
159
|
-
assert_equal 99, expectation
|
168
|
+
assert_equal 99, invoke(expectation)
|
169
|
+
assert_equal 99, invoke(expectation)
|
160
170
|
end
|
161
171
|
|
162
172
|
def test_should_return_specified_values_on_consecutive_calls
|
163
173
|
expectation = new_expectation.returns(99, 100, 101)
|
164
|
-
assert_equal 99, expectation
|
165
|
-
assert_equal 100, expectation
|
166
|
-
assert_equal 101, expectation
|
174
|
+
assert_equal 99, invoke(expectation)
|
175
|
+
assert_equal 100, invoke(expectation)
|
176
|
+
assert_equal 101, invoke(expectation)
|
167
177
|
end
|
168
178
|
|
169
179
|
def test_should_return_specified_values_on_consecutive_calls_even_if_values_are_modified
|
170
180
|
values = [99, 100, 101]
|
171
181
|
expectation = new_expectation.returns(*values)
|
172
182
|
values.shift
|
173
|
-
assert_equal 99, expectation
|
174
|
-
assert_equal 100, expectation
|
175
|
-
assert_equal 101, expectation
|
183
|
+
assert_equal 99, invoke(expectation)
|
184
|
+
assert_equal 100, invoke(expectation)
|
185
|
+
assert_equal 101, invoke(expectation)
|
176
186
|
end
|
177
187
|
|
178
188
|
def test_should_return_nil_by_default
|
179
|
-
assert_nil new_expectation
|
189
|
+
assert_nil invoke(new_expectation)
|
180
190
|
end
|
181
191
|
|
182
192
|
def test_should_return_nil_if_no_value_specified
|
183
|
-
|
184
|
-
assert_nil expectation.invoke
|
193
|
+
assert_nil invoke(new_expectation.returns)
|
185
194
|
end
|
186
195
|
|
187
196
|
def test_should_raise_runtime_exception
|
188
|
-
|
189
|
-
assert_raise(RuntimeError) { expectation.invoke }
|
197
|
+
assert_raises(RuntimeError) { invoke(new_expectation.raises) }
|
190
198
|
end
|
191
199
|
|
192
200
|
def test_should_raise_custom_exception
|
193
201
|
exception = Class.new(Exception)
|
194
|
-
|
195
|
-
assert_raise(exception) { expectation.invoke }
|
202
|
+
assert_raises(exception) { invoke(new_expectation.raises(exception)) }
|
196
203
|
end
|
197
204
|
|
198
205
|
def test_should_raise_same_instance_of_custom_exception
|
199
206
|
exception_klass = Class.new(StandardError)
|
200
207
|
expected_exception = exception_klass.new
|
201
|
-
|
202
|
-
actual_exception = assert_raise(exception_klass) { expectation.invoke }
|
208
|
+
actual_exception = assert_raises(exception_klass) { invoke(new_expectation.raises(expected_exception)) }
|
203
209
|
assert_same expected_exception, actual_exception
|
204
210
|
end
|
205
211
|
|
206
212
|
def test_should_use_the_default_exception_message
|
207
|
-
|
208
|
-
exception = assert_raise(Exception) { expectation.invoke }
|
213
|
+
exception = assert_raises(Exception) { invoke(new_expectation.raises(Exception)) }
|
209
214
|
assert_equal Exception.new.message, exception.message
|
210
215
|
end
|
211
216
|
|
212
217
|
def test_should_raise_custom_exception_with_message
|
213
218
|
exception_msg = 'exception message'
|
214
|
-
|
215
|
-
exception = assert_raise(Exception) { expectation.invoke }
|
219
|
+
exception = assert_raises(Exception) { invoke(new_expectation.raises(Exception, exception_msg)) }
|
216
220
|
assert_equal exception_msg, exception.message
|
217
221
|
end
|
218
222
|
|
219
223
|
def test_should_return_values_then_raise_exception
|
220
224
|
expectation = new_expectation.returns(1, 2).then.raises
|
221
|
-
assert_equal 1, expectation
|
222
|
-
assert_equal 2, expectation
|
223
|
-
|
225
|
+
assert_equal 1, invoke(expectation)
|
226
|
+
assert_equal 2, invoke(expectation)
|
227
|
+
assert_raises(RuntimeError) { invoke(expectation) }
|
224
228
|
end
|
225
229
|
|
226
230
|
def test_should_raise_exception_then_return_values
|
227
231
|
expectation = new_expectation.raises.then.returns(1, 2)
|
228
|
-
|
229
|
-
assert_equal 1, expectation
|
230
|
-
assert_equal 2, expectation
|
232
|
+
assert_raises(RuntimeError) { invoke(expectation) }
|
233
|
+
assert_equal 1, invoke(expectation)
|
234
|
+
assert_equal 2, invoke(expectation)
|
231
235
|
end
|
232
236
|
|
233
237
|
def test_should_verify_successfully_if_expected_call_was_made
|
234
238
|
expectation = new_expectation
|
235
|
-
expectation
|
239
|
+
invoke(expectation)
|
236
240
|
assert expectation.verified?
|
237
241
|
end
|
238
242
|
|
239
243
|
def test_should_not_verify_successfully_if_call_expected_once_but_invoked_twice
|
240
244
|
expectation = new_expectation.once
|
241
|
-
expectation
|
242
|
-
expectation
|
245
|
+
invoke(expectation)
|
246
|
+
invoke(expectation)
|
243
247
|
assert !expectation.verified?
|
244
248
|
end
|
245
249
|
|
246
250
|
def test_should_not_verify_successfully_if_call_expected_once_but_not_invoked
|
247
|
-
|
248
|
-
assert !expectation.verified?
|
251
|
+
assert !new_expectation.once.verified?
|
249
252
|
end
|
250
253
|
|
251
254
|
def test_should_verify_successfully_if_call_expected_once_and_invoked_once
|
252
255
|
expectation = new_expectation.once
|
253
|
-
expectation
|
256
|
+
invoke(expectation)
|
254
257
|
assert expectation.verified?
|
255
258
|
end
|
256
259
|
|
257
260
|
def test_should_not_verify_successfully_if_call_expected_twice_and_invoked_three_times
|
258
261
|
expectation = new_expectation.twice
|
259
|
-
expectation
|
260
|
-
expectation
|
261
|
-
expectation
|
262
|
+
invoke(expectation)
|
263
|
+
invoke(expectation)
|
264
|
+
invoke(expectation)
|
262
265
|
assert !expectation.verified?
|
263
266
|
end
|
264
267
|
|
265
268
|
def test_should_not_verify_successfully_if_call_expected_twice_but_invoked_once
|
266
269
|
expectation = new_expectation.twice
|
267
|
-
expectation
|
270
|
+
invoke(expectation)
|
268
271
|
assert !expectation.verified?
|
269
272
|
end
|
270
273
|
|
271
274
|
def test_should_verify_successfully_if_call_expected_twice_and_invoked_twice
|
272
275
|
expectation = new_expectation.twice
|
273
|
-
expectation
|
274
|
-
expectation
|
276
|
+
invoke(expectation)
|
277
|
+
invoke(expectation)
|
275
278
|
assert expectation.verified?
|
276
279
|
end
|
277
280
|
|
278
281
|
def test_should_verify_successfully_if_expected_call_was_made_at_least_once
|
279
282
|
expectation = new_expectation.at_least_once
|
280
|
-
3.times { expectation
|
283
|
+
3.times { invoke(expectation) }
|
281
284
|
assert expectation.verified?
|
282
285
|
end
|
283
286
|
|
284
287
|
def test_should_not_verify_successfully_if_expected_call_was_not_made_at_least_once
|
285
288
|
expectation = new_expectation.with(1, 2, 3).at_least_once
|
286
289
|
assert !expectation.verified?
|
287
|
-
assert_match(/expected at least once,
|
290
|
+
assert_match(/expected at least once, invoked never/i, expectation.mocha_inspect)
|
288
291
|
end
|
289
292
|
|
290
293
|
def test_should_verify_successfully_if_expected_call_was_made_expected_number_of_times
|
291
294
|
expectation = new_expectation.times(2)
|
292
|
-
2.times { expectation
|
295
|
+
2.times { invoke(expectation) }
|
293
296
|
assert expectation.verified?
|
294
297
|
end
|
295
298
|
|
296
299
|
def test_should_not_verify_successfully_if_expected_call_was_made_too_few_times
|
297
300
|
expectation = new_expectation.times(2)
|
298
|
-
1.times { expectation
|
301
|
+
1.times { invoke(expectation) }
|
299
302
|
assert !expectation.verified?
|
300
303
|
assert_match(/expected exactly twice, invoked once/i, expectation.mocha_inspect)
|
301
304
|
end
|
302
305
|
|
303
306
|
def test_should_not_verify_successfully_if_expected_call_was_made_too_many_times
|
304
307
|
expectation = new_expectation.times(2)
|
305
|
-
3.times { expectation
|
308
|
+
3.times { invoke(expectation) }
|
306
309
|
assert !expectation.verified?
|
307
310
|
end
|
308
311
|
|
309
312
|
def test_should_increment_assertion_counter_for_expectation_because_it_does_need_verifyng
|
310
313
|
expectation = new_expectation
|
311
|
-
expectation
|
314
|
+
invoke(expectation)
|
312
315
|
assertion_counter = SimpleCounter.new
|
313
316
|
expectation.verified?(assertion_counter)
|
314
317
|
assert_equal 1, assertion_counter.count
|
315
318
|
end
|
316
319
|
|
317
320
|
def test_should_not_increment_assertion_counter_for_stub_because_it_does_not_need_verifying
|
318
|
-
stub = Expectation.new(nil, :expected_method).at_least(0)
|
319
321
|
assertion_counter = SimpleCounter.new
|
320
|
-
|
322
|
+
Expectation.new(nil, :expected_method).at_least(0).verified?(assertion_counter)
|
321
323
|
assert_equal 0, assertion_counter.count
|
322
324
|
end
|
323
325
|
|
@@ -381,7 +383,7 @@ class ExpectationTest < Mocha::TestCase
|
|
381
383
|
expectation = Expectation.new(nil, :method_one)
|
382
384
|
expectation.add_ordering_constraint(constraint_one)
|
383
385
|
expectation.add_ordering_constraint(constraint_two)
|
384
|
-
assert expectation.match?(:method_one)
|
386
|
+
assert expectation.match?(Invocation.new(:irrelevant, :method_one))
|
385
387
|
end
|
386
388
|
|
387
389
|
def test_should_not_match_if_one_ordering_constraints_does_not_allow_invocation_now
|
@@ -390,29 +392,28 @@ class ExpectationTest < Mocha::TestCase
|
|
390
392
|
expectation = Expectation.new(nil, :method_one)
|
391
393
|
expectation.add_ordering_constraint(constraint_one)
|
392
394
|
expectation.add_ordering_constraint(constraint_two)
|
393
|
-
assert !expectation.match?(:method_one)
|
395
|
+
assert !expectation.match?(Invocation.new(:irrelevant, :method_one))
|
394
396
|
end
|
395
397
|
|
396
398
|
def test_should_not_be_satisfied_when_required_invocation_has_not_been_made
|
397
|
-
|
398
|
-
assert !expectation.satisfied?
|
399
|
+
assert !Expectation.new(nil, :method_one).times(1).satisfied?
|
399
400
|
end
|
400
401
|
|
401
402
|
def test_should_be_satisfied_when_required_invocation_has_been_made
|
402
403
|
expectation = Expectation.new(nil, :method_one).times(1)
|
403
|
-
expectation
|
404
|
+
invoke(expectation)
|
404
405
|
assert expectation.satisfied?
|
405
406
|
end
|
406
407
|
|
407
408
|
def test_should_not_be_satisfied_when_minimum_number_of_invocations_has_not_been_made
|
408
409
|
expectation = Expectation.new(nil, :method_one).at_least(2)
|
409
|
-
expectation
|
410
|
+
invoke(expectation)
|
410
411
|
assert !expectation.satisfied?
|
411
412
|
end
|
412
413
|
|
413
414
|
def test_should_be_satisfied_when_minimum_number_of_invocations_has_been_made
|
414
415
|
expectation = Expectation.new(nil, :method_one).at_least(2)
|
415
|
-
2.times { expectation
|
416
|
+
2.times { invoke(expectation) }
|
416
417
|
assert expectation.satisfied?
|
417
418
|
end
|
418
419
|
|
@@ -457,7 +458,7 @@ class ExpectationTest < Mocha::TestCase
|
|
457
458
|
|
458
459
|
expectation.then(state)
|
459
460
|
|
460
|
-
expectation
|
461
|
+
invoke(expectation)
|
461
462
|
assert state.active?
|
462
463
|
end
|
463
464
|
|
@@ -466,10 +467,10 @@ class ExpectationTest < Mocha::TestCase
|
|
466
467
|
expectation = Expectation.new(nil, :method_one)
|
467
468
|
|
468
469
|
expectation.when(state)
|
469
|
-
assert !expectation.match?(:method_one)
|
470
|
+
assert !expectation.match?(Invocation.new(:irrelevant, :method_one))
|
470
471
|
|
471
472
|
state.activate
|
472
|
-
assert expectation.match?(:method_one)
|
473
|
+
assert expectation.match?(Invocation.new(:irrelevant, :method_one))
|
473
474
|
end
|
474
475
|
|
475
476
|
def test_should_include_default_representation_of_object_in_inspect
|
@@ -477,8 +478,7 @@ class ExpectationTest < Mocha::TestCase
|
|
477
478
|
class << object
|
478
479
|
define_method(:inspect) { 'mock' }
|
479
480
|
end
|
480
|
-
|
481
|
-
assert_match Regexp.new('^#<Expectation:0x[0-9A-Fa-f]{1,12} .* >$'), expectation.inspect
|
481
|
+
assert_match Regexp.new('^#<Expectation:0x[0-9A-Fa-f]{1,12} .* >$'), Expectation.new(object, :method_one).inspect
|
482
482
|
end
|
483
483
|
|
484
484
|
def test_should_include_output_of_mocha_inspect_in_inspect
|