mocha 1.10.2 → 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/.yardopts +1 -0
- data/CONTRIBUTING.md +1 -1
- data/README.md +28 -30
- data/RELEASE.md +87 -0
- data/Rakefile +7 -5
- data/lib/mocha/api.rb +2 -3
- data/lib/mocha/block_matcher.rb +31 -0
- data/lib/mocha/cardinality.rb +30 -27
- data/lib/mocha/configuration.rb +2 -2
- data/lib/mocha/expectation.rb +71 -30
- data/lib/mocha/inspect.rb +6 -4
- data/lib/mocha/invocation.rb +9 -5
- data/lib/mocha/mock.rb +41 -15
- data/lib/mocha/mockery.rb +17 -27
- data/lib/mocha/parameter_matchers.rb +1 -0
- 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/is_a.rb +2 -3
- data/lib/mocha/parameter_matchers/not.rb +2 -3
- data/lib/mocha/state_machine.rb +31 -40
- data/lib/mocha/stubbed_method.rb +4 -6
- data/lib/mocha/version.rb +1 -1
- data/lib/mocha/yield_parameters.rb +5 -11
- data/mocha.gemspec +13 -7
- metadata +8 -210
- data/bin/build-matrix +0 -82
- data/docs/CNAME +0 -1
- data/docs/Mocha.html +0 -254
- data/docs/Mocha/API.html +0 -1287
- data/docs/Mocha/ClassMethods.html +0 -264
- data/docs/Mocha/Configuration.html +0 -1525
- data/docs/Mocha/Expectation.html +0 -2654
- 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 -1237
- data/docs/Mocha/ObjectMethods.html +0 -765
- data/docs/Mocha/ParameterMatchers.html +0 -2961
- 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 -974
- 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 -635
- 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.minitest.5.11.3 +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/multiple_yields.rb +0 -15
- data/lib/mocha/no_yields.rb +0 -5
- data/lib/mocha/pretty_parameters.rb +0 -24
- data/lib/mocha/single_yield.rb +0 -13
- data/test/acceptance/acceptance_test_helper.rb +0 -41
- 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 -61
- data/test/acceptance/issue_272_test.rb +0 -50
- 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 -96
- data/test/acceptance/mocha_test_result_test.rb +0 -83
- data/test/acceptance/mock_built_with_first_argument_type_being_string_test.rb +0 -99
- data/test/acceptance/mock_test.rb +0 -139
- data/test/acceptance/mocked_methods_dispatch_test.rb +0 -75
- data/test/acceptance/multiple_expectations_failure_message_test.rb +0 -66
- 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 -93
- 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/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 -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/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/multiple_yields_test.rb +0 -16
- data/test/unit/no_yields_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/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 -23
- data/test/unit/yield_parameters_test.rb +0 -91
@@ -1,37 +0,0 @@
|
|
1
|
-
require File.expand_path('../../test_helper', __FILE__)
|
2
|
-
|
3
|
-
require 'mocha/change_state_side_effect'
|
4
|
-
|
5
|
-
class ChangeStateSideEffectTest < Mocha::TestCase
|
6
|
-
include Mocha
|
7
|
-
|
8
|
-
class FakeState
|
9
|
-
attr_reader :active
|
10
|
-
attr_writer :description
|
11
|
-
|
12
|
-
def activate
|
13
|
-
@active = true
|
14
|
-
end
|
15
|
-
|
16
|
-
def mocha_inspect
|
17
|
-
@description
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_should_activate_the_given_state
|
22
|
-
state = FakeState.new
|
23
|
-
side_effect = ChangeStateSideEffect.new(state)
|
24
|
-
|
25
|
-
side_effect.perform
|
26
|
-
|
27
|
-
assert state.active
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_should_describe_itself_in_terms_of_the_activated_state
|
31
|
-
state = FakeState.new
|
32
|
-
state.description = 'the-new-state'
|
33
|
-
side_effect = ChangeStateSideEffect.new(state)
|
34
|
-
|
35
|
-
assert_equal 'then the-new-state', side_effect.mocha_inspect
|
36
|
-
end
|
37
|
-
end
|
@@ -1,69 +0,0 @@
|
|
1
|
-
require File.expand_path('../../test_helper', __FILE__)
|
2
|
-
require 'mocha/class_methods'
|
3
|
-
require 'mocha/object_methods'
|
4
|
-
require 'mocha/mockery'
|
5
|
-
require 'mocha/names'
|
6
|
-
|
7
|
-
class ClassMethodsTest < Mocha::TestCase
|
8
|
-
def setup
|
9
|
-
Mocha::Mockery.setup
|
10
|
-
@klass = Class.new.extend(Mocha::ClassMethods, Mocha::ObjectMethods)
|
11
|
-
end
|
12
|
-
|
13
|
-
def teardown
|
14
|
-
Mocha::Mockery.teardown
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_should_build_any_instance_object
|
18
|
-
any_instance = @klass.any_instance
|
19
|
-
assert_not_nil any_instance
|
20
|
-
assert any_instance.is_a?(Mocha::ClassMethods::AnyInstance)
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_should_return_same_any_instance_object
|
24
|
-
any_instance1 = @klass.any_instance
|
25
|
-
any_instance2 = @klass.any_instance
|
26
|
-
assert_equal any_instance1, any_instance2
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_any_instance_should_build_mocha_referring_to_klass
|
30
|
-
mocha = @klass.any_instance.mocha
|
31
|
-
assert_not_nil mocha
|
32
|
-
assert mocha.is_a?(Mocha::Mock)
|
33
|
-
expected_name = Mocha::ImpersonatingAnyInstanceName.new(@klass).mocha_inspect
|
34
|
-
assert_equal expected_name, mocha.mocha_inspect
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_any_instance_should_not_build_mocha_if_instantiate_is_false
|
38
|
-
assert_nil @klass.any_instance.mocha(false)
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_any_instance_should_reuse_existing_mocha
|
42
|
-
mocha1 = @klass.any_instance.mocha
|
43
|
-
mocha2 = @klass.any_instance.mocha
|
44
|
-
assert_equal mocha1, mocha2
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_any_instance_should_reuse_existing_mocha_even_if_instantiate_is_false
|
48
|
-
mocha1 = @klass.any_instance.mocha
|
49
|
-
mocha2 = @klass.any_instance.mocha(false)
|
50
|
-
assert_equal mocha1, mocha2
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_should_use_stubba_class_method_for_class
|
54
|
-
assert_equal Mocha::InstanceMethod, @klass.stubba_method
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_should_use_stubba_class_method_for_any_instance
|
58
|
-
assert_equal Mocha::AnyInstanceMethod, @klass.any_instance.stubba_method
|
59
|
-
end
|
60
|
-
|
61
|
-
def test_should_stub_self_for_class
|
62
|
-
assert_equal @klass, @klass.stubba_object
|
63
|
-
end
|
64
|
-
|
65
|
-
def test_should_stub_relevant_class_for_any_instance
|
66
|
-
any_instance = @klass.any_instance
|
67
|
-
assert_equal @klass, any_instance.stubba_object
|
68
|
-
end
|
69
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
require File.expand_path('../../test_helper', __FILE__)
|
2
|
-
require 'mocha/configuration'
|
3
|
-
|
4
|
-
class ConfigurationTest < Mocha::TestCase
|
5
|
-
def test_allow_temporarily_changes_config_when_given_block
|
6
|
-
Mocha.configure { |c| c.stubbing_method_unnecessarily = :warn }
|
7
|
-
yielded = false
|
8
|
-
Mocha::Configuration.override(:stubbing_method_unnecessarily => :allow) do
|
9
|
-
yielded = true
|
10
|
-
assert_equal :allow, Mocha.configuration.stubbing_method_unnecessarily
|
11
|
-
end
|
12
|
-
assert yielded
|
13
|
-
assert_equal :warn, Mocha.configuration.stubbing_method_unnecessarily
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_prevent_temporarily_changes_config_when_given_block
|
17
|
-
Mocha.configure { |c| c.stubbing_method_unnecessarily = :allow }
|
18
|
-
yielded = false
|
19
|
-
Mocha::Configuration.override(:stubbing_method_unnecessarily => :prevent) do
|
20
|
-
yielded = true
|
21
|
-
assert_equal :prevent, Mocha.configuration.stubbing_method_unnecessarily
|
22
|
-
end
|
23
|
-
assert yielded
|
24
|
-
assert_equal :allow, Mocha.configuration.stubbing_method_unnecessarily
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_warn_when_temporarily_changes_config_when_given_block
|
28
|
-
Mocha.configure { |c| c.stubbing_method_unnecessarily = :allow }
|
29
|
-
yielded = false
|
30
|
-
Mocha::Configuration.override(:stubbing_method_unnecessarily => :warn) do
|
31
|
-
yielded = true
|
32
|
-
assert_equal :warn, Mocha.configuration.stubbing_method_unnecessarily
|
33
|
-
end
|
34
|
-
assert yielded
|
35
|
-
assert_equal :allow, Mocha.configuration.stubbing_method_unnecessarily
|
36
|
-
end
|
37
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
require File.expand_path('../../test_helper', __FILE__)
|
2
|
-
require 'mocha/inspect'
|
3
|
-
|
4
|
-
class DateTimeInspectTest < Mocha::TestCase
|
5
|
-
def test_should_use_include_date_in_seconds
|
6
|
-
time = Time.now
|
7
|
-
assert_equal "#{time.inspect} (#{time.to_f} secs)", time.mocha_inspect
|
8
|
-
end
|
9
|
-
|
10
|
-
def test_should_use_to_s_for_date
|
11
|
-
date = Date.new(2006, 1, 1)
|
12
|
-
assert_equal date.to_s, date.mocha_inspect
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_should_use_to_s_for_datetime
|
16
|
-
datetime = DateTime.new(2006, 1, 1) # rubocop:disable Style/DateTime
|
17
|
-
assert_equal datetime.to_s, datetime.mocha_inspect
|
18
|
-
end
|
19
|
-
end
|
@@ -1,45 +0,0 @@
|
|
1
|
-
require File.expand_path('../../test_helper', __FILE__)
|
2
|
-
|
3
|
-
require 'mocha/invocation'
|
4
|
-
require 'mocha/exception_raiser'
|
5
|
-
require 'timeout'
|
6
|
-
|
7
|
-
class ExceptionRaiserTest < Mocha::TestCase
|
8
|
-
include Mocha
|
9
|
-
|
10
|
-
def new_invocation
|
11
|
-
Invocation.new(:irrelevant, :irrelevant)
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_should_raise_exception_with_specified_class_and_default_message
|
15
|
-
exception_class = Class.new(StandardError)
|
16
|
-
raiser = ExceptionRaiser.new(exception_class, nil)
|
17
|
-
exception = assert_raises(exception_class) { raiser.evaluate(new_invocation) }
|
18
|
-
assert_equal exception_class.to_s, exception.message
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_should_raise_exception_with_specified_class_and_message
|
22
|
-
exception_class = Class.new(StandardError)
|
23
|
-
raiser = ExceptionRaiser.new(exception_class, 'message')
|
24
|
-
exception = assert_raises(exception_class) { raiser.evaluate(new_invocation) }
|
25
|
-
assert_equal 'message', exception.message
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_should_raise_exception_instance
|
29
|
-
exception_class = Class.new(StandardError)
|
30
|
-
raiser = ExceptionRaiser.new(exception_class.new('message'), nil)
|
31
|
-
exception = assert_raises(exception_class) { raiser.evaluate(new_invocation) }
|
32
|
-
assert_equal 'message', exception.message
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_should_raise_interrupt_exception_with_default_message_so_it_works_in_ruby_1_8_6
|
36
|
-
raiser = ExceptionRaiser.new(Interrupt, nil)
|
37
|
-
assert_raises(Interrupt) { raiser.evaluate(new_invocation) }
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_should_raise_subclass_of_interrupt_exception_with_default_message_so_it_works_in_ruby_1_8_6
|
41
|
-
exception_class = Class.new(Interrupt)
|
42
|
-
raiser = ExceptionRaiser.new(exception_class, nil)
|
43
|
-
assert_raises(exception_class) { raiser.evaluate(new_invocation) }
|
44
|
-
end
|
45
|
-
end
|
@@ -1,82 +0,0 @@
|
|
1
|
-
require File.expand_path('../../test_helper', __FILE__)
|
2
|
-
require 'mocha/expectation_list'
|
3
|
-
require 'mocha/expectation'
|
4
|
-
require 'mocha/invocation'
|
5
|
-
require 'set'
|
6
|
-
require 'method_definer'
|
7
|
-
|
8
|
-
class ExpectationListTest < Mocha::TestCase
|
9
|
-
include MethodDefiner
|
10
|
-
include Mocha
|
11
|
-
|
12
|
-
def test_should_return_added_expectation
|
13
|
-
expectation_list = ExpectationList.new
|
14
|
-
expectation = Expectation.new(nil, :my_method)
|
15
|
-
assert_same expectation, expectation_list.add(expectation)
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_should_find_matching_expectation
|
19
|
-
expectation_list = ExpectationList.new
|
20
|
-
expectation1 = Expectation.new(nil, :my_method).with(:argument1, :argument2)
|
21
|
-
expectation2 = Expectation.new(nil, :my_method).with(:argument3, :argument4)
|
22
|
-
expectation_list.add(expectation1)
|
23
|
-
expectation_list.add(expectation2)
|
24
|
-
assert_same expectation1, expectation_list.match(Invocation.new(:irrelevant, :my_method, :argument1, :argument2))
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_should_remove_all_expectations_matching_method_name
|
28
|
-
expectation_list = ExpectationList.new
|
29
|
-
expectation1 = Expectation.new(nil, :method_one).with(:argument1, :argument2)
|
30
|
-
expectation2 = Expectation.new(nil, :method_one).with(:argument3, :argument4)
|
31
|
-
expectation3 = Expectation.new(nil, :method_two)
|
32
|
-
expectation_list.add(expectation1)
|
33
|
-
expectation_list.add(expectation2)
|
34
|
-
expectation_list.add(expectation3)
|
35
|
-
expectation_list.remove_all_matching_method(:method_one)
|
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))
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_should_find_most_recent_matching_expectation
|
42
|
-
expectation_list = ExpectationList.new
|
43
|
-
expectation1 = Expectation.new(nil, :my_method).with(:argument1, :argument2)
|
44
|
-
expectation2 = Expectation.new(nil, :my_method).with(:argument1, :argument2)
|
45
|
-
expectation_list.add(expectation1)
|
46
|
-
expectation_list.add(expectation2)
|
47
|
-
assert_same expectation2, expectation_list.match(Invocation.new(:irrelevant, :my_method, :argument1, :argument2))
|
48
|
-
end
|
49
|
-
|
50
|
-
def test_should_find_matching_expectation_allowing_invocation
|
51
|
-
expectation_list = ExpectationList.new
|
52
|
-
expectation1 = Expectation.new(nil, :my_method).with(:argument1, :argument2)
|
53
|
-
expectation2 = Expectation.new(nil, :my_method).with(:argument3, :argument4)
|
54
|
-
define_instance_method(expectation1, :invocations_allowed?) { true }
|
55
|
-
define_instance_method(expectation2, :invocations_allowed?) { true }
|
56
|
-
expectation_list.add(expectation1)
|
57
|
-
expectation_list.add(expectation2)
|
58
|
-
assert_same expectation1, expectation_list.match_allowing_invocation(Invocation.new(:irrelevant, :my_method, :argument1, :argument2))
|
59
|
-
end
|
60
|
-
|
61
|
-
def test_should_find_most_recent_matching_expectation_allowing_invocation
|
62
|
-
expectation_list = ExpectationList.new
|
63
|
-
expectation1 = Expectation.new(nil, :my_method)
|
64
|
-
expectation2 = Expectation.new(nil, :my_method)
|
65
|
-
define_instance_method(expectation1, :invocations_allowed?) { true }
|
66
|
-
define_instance_method(expectation2, :invocations_allowed?) { false }
|
67
|
-
expectation_list.add(expectation1)
|
68
|
-
expectation_list.add(expectation2)
|
69
|
-
assert_same expectation1, expectation_list.match_allowing_invocation(Invocation.new(:irrelevant, :my_method))
|
70
|
-
end
|
71
|
-
|
72
|
-
def test_should_combine_two_expectation_lists_into_one
|
73
|
-
expectation_list1 = ExpectationList.new
|
74
|
-
expectation_list2 = ExpectationList.new
|
75
|
-
expectation1 = Expectation.new(nil, :my_method)
|
76
|
-
expectation2 = Expectation.new(nil, :my_method)
|
77
|
-
expectation_list1.add(expectation1)
|
78
|
-
expectation_list2.add(expectation2)
|
79
|
-
expectation_list = expectation_list1 + expectation_list2
|
80
|
-
assert_equal [expectation1, expectation2], expectation_list.to_a
|
81
|
-
end
|
82
|
-
end
|
@@ -1,492 +0,0 @@
|
|
1
|
-
require File.expand_path('../../test_helper', __FILE__)
|
2
|
-
require 'mocha/expectation'
|
3
|
-
require 'mocha/invocation'
|
4
|
-
require 'mocha/sequence'
|
5
|
-
require 'mocha/configuration'
|
6
|
-
require 'mocha/deprecation'
|
7
|
-
require 'execution_point'
|
8
|
-
require 'simple_counter'
|
9
|
-
require 'deprecation_disabler'
|
10
|
-
|
11
|
-
class ExpectationTest < Mocha::TestCase
|
12
|
-
include Mocha
|
13
|
-
|
14
|
-
def new_expectation
|
15
|
-
Expectation.new(nil, :expected_method)
|
16
|
-
end
|
17
|
-
|
18
|
-
def invoke(expectation, &block)
|
19
|
-
expectation.invoke(Invocation.new(:irrelevant, :expected_method, &block))
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_should_match_calls_to_same_method_with_any_parameters
|
23
|
-
assert new_expectation.match?(Invocation.new(:irrelevant, :expected_method, 1, 2, 3))
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_should_match_calls_to_same_method_with_exactly_zero_parameters
|
27
|
-
assert new_expectation.with.match?(Invocation.new(:irrelevant, :expected_method))
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_should_not_match_calls_to_same_method_with_more_than_zero_parameters
|
31
|
-
assert !new_expectation.with.match?(Invocation.new(:irrelevant, :expected_method, 1, 2, 3))
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_should_match_calls_to_same_method_with_expected_parameter_values
|
35
|
-
assert new_expectation.with(1, 2, 3).match?(Invocation.new(:irrelevant, :expected_method, 1, 2, 3))
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_should_match_calls_to_same_method_with_parameters_constrained_as_expected
|
39
|
-
expectation = new_expectation.with { |x, y, z| x + y == z }
|
40
|
-
assert expectation.match?(Invocation.new(:irrelevant, :expected_method, 1, 2, 3))
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_should_not_match_calls_to_different_method_with_parameters_constrained_as_expected
|
44
|
-
expectation = new_expectation.with { |x, y, z| x + y == z }
|
45
|
-
assert !expectation.match?(Invocation.new(:irrelevant, :different_method, 1, 2, 3))
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_should_not_match_calls_to_different_methods_with_no_parameters
|
49
|
-
assert !new_expectation.match?(Invocation.new(:irrelevant, :unexpected_method))
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_should_not_match_calls_to_same_method_with_too_few_parameters
|
53
|
-
assert !new_expectation.with(1, 2, 3).match?(Invocation.new(:irrelevant, :expected_method, 1, 2))
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_should_not_match_calls_to_same_method_with_too_many_parameters
|
57
|
-
assert !new_expectation.with(1, 2).match?(Invocation.new(:irrelevant, :expected_method, 1, 2, 3))
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_should_not_match_calls_to_same_method_with_unexpected_parameter_values
|
61
|
-
assert !new_expectation.with(1, 2, 3).match?(Invocation.new(:irrelevant, :expected_method, 1, 0, 3))
|
62
|
-
end
|
63
|
-
|
64
|
-
def test_should_not_match_calls_to_same_method_with_parameters_not_constrained_as_expected
|
65
|
-
expectation = new_expectation.with { |x, y, z| x + y == z }
|
66
|
-
assert !expectation.match?(Invocation.new(:irrelevant, :expected_method, 1, 0, 3))
|
67
|
-
end
|
68
|
-
|
69
|
-
def test_should_allow_invocations_until_expected_invocation_count_is_one_and_actual_invocation_count_would_be_two
|
70
|
-
expectation = new_expectation.times(1)
|
71
|
-
assert expectation.invocations_allowed?
|
72
|
-
invoke(expectation)
|
73
|
-
assert !expectation.invocations_allowed?
|
74
|
-
end
|
75
|
-
|
76
|
-
def test_should_allow_invocations_until_expected_invocation_count_is_two_and_actual_invocation_count_would_be_three
|
77
|
-
expectation = new_expectation.times(2)
|
78
|
-
2.times do
|
79
|
-
assert expectation.invocations_allowed?
|
80
|
-
invoke(expectation)
|
81
|
-
end
|
82
|
-
assert !expectation.invocations_allowed?
|
83
|
-
end
|
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
|
86
|
-
expectation = new_expectation.times(2..3)
|
87
|
-
3.times do
|
88
|
-
assert expectation.invocations_allowed?
|
89
|
-
invoke(expectation)
|
90
|
-
end
|
91
|
-
assert !expectation.invocations_allowed?
|
92
|
-
end
|
93
|
-
|
94
|
-
def test_should_store_provided_backtrace
|
95
|
-
backtrace = Object.new
|
96
|
-
assert_equal backtrace, Expectation.new(nil, :expected_method, backtrace).backtrace
|
97
|
-
end
|
98
|
-
|
99
|
-
# rubocop:disable Style/Semicolon
|
100
|
-
def test_should_default_backtrace_to_caller
|
101
|
-
execution_point = ExecutionPoint.current; expectation = Expectation.new(nil, :expected_method)
|
102
|
-
assert_equal execution_point, ExecutionPoint.new(expectation.backtrace)
|
103
|
-
end
|
104
|
-
# rubocop:enable Style/Semicolon
|
105
|
-
|
106
|
-
def test_should_not_yield
|
107
|
-
yielded = false
|
108
|
-
invoke(new_expectation) { yielded = true }
|
109
|
-
assert_equal false, yielded
|
110
|
-
end
|
111
|
-
|
112
|
-
def test_should_yield_no_parameters
|
113
|
-
yielded_parameters = nil
|
114
|
-
invoke(new_expectation.yields) { |*parameters| yielded_parameters = parameters }
|
115
|
-
assert_equal [], yielded_parameters
|
116
|
-
end
|
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
|
-
|
134
|
-
def test_should_yield_with_specified_parameters
|
135
|
-
yielded_parameters = nil
|
136
|
-
invoke(new_expectation.yields(1, 2, 3)) { |*parameters| yielded_parameters = parameters }
|
137
|
-
assert_equal [1, 2, 3], yielded_parameters
|
138
|
-
end
|
139
|
-
|
140
|
-
def test_should_yield_different_parameters_on_consecutive_invocations
|
141
|
-
expectation = new_expectation.yields(1, 2, 3).yields(4, 5)
|
142
|
-
yielded_parameters = []
|
143
|
-
invoke(expectation) { |*parameters| yielded_parameters << parameters }
|
144
|
-
invoke(expectation) { |*parameters| yielded_parameters << parameters }
|
145
|
-
assert_equal [[1, 2, 3], [4, 5]], yielded_parameters
|
146
|
-
end
|
147
|
-
|
148
|
-
def test_should_yield_multiple_times_for_single_invocation
|
149
|
-
yielded_parameters = []
|
150
|
-
invoke(new_expectation.multiple_yields([1, 2, 3], [4, 5])) { |*parameters| yielded_parameters << parameters }
|
151
|
-
assert_equal [[1, 2, 3], [4, 5]], yielded_parameters
|
152
|
-
end
|
153
|
-
|
154
|
-
def test_should_yield_multiple_times_for_first_invocation_and_once_for_second_invocation
|
155
|
-
expectation = new_expectation.multiple_yields([1, 2, 3], [4, 5]).then.yields(6, 7)
|
156
|
-
yielded_parameters = []
|
157
|
-
invoke(expectation) { |*parameters| yielded_parameters << parameters }
|
158
|
-
invoke(expectation) { |*parameters| yielded_parameters << parameters }
|
159
|
-
assert_equal [[1, 2, 3], [4, 5], [6, 7]], yielded_parameters
|
160
|
-
end
|
161
|
-
|
162
|
-
def test_should_return_specified_value
|
163
|
-
assert_equal 99, invoke(new_expectation.returns(99))
|
164
|
-
end
|
165
|
-
|
166
|
-
def test_should_return_same_specified_value_multiple_times
|
167
|
-
expectation = new_expectation.returns(99)
|
168
|
-
assert_equal 99, invoke(expectation)
|
169
|
-
assert_equal 99, invoke(expectation)
|
170
|
-
end
|
171
|
-
|
172
|
-
def test_should_return_specified_values_on_consecutive_calls
|
173
|
-
expectation = new_expectation.returns(99, 100, 101)
|
174
|
-
assert_equal 99, invoke(expectation)
|
175
|
-
assert_equal 100, invoke(expectation)
|
176
|
-
assert_equal 101, invoke(expectation)
|
177
|
-
end
|
178
|
-
|
179
|
-
def test_should_return_specified_values_on_consecutive_calls_even_if_values_are_modified
|
180
|
-
values = [99, 100, 101]
|
181
|
-
expectation = new_expectation.returns(*values)
|
182
|
-
values.shift
|
183
|
-
assert_equal 99, invoke(expectation)
|
184
|
-
assert_equal 100, invoke(expectation)
|
185
|
-
assert_equal 101, invoke(expectation)
|
186
|
-
end
|
187
|
-
|
188
|
-
def test_should_return_nil_by_default
|
189
|
-
assert_nil invoke(new_expectation)
|
190
|
-
end
|
191
|
-
|
192
|
-
def test_should_return_nil_if_no_value_specified
|
193
|
-
assert_nil invoke(new_expectation.returns)
|
194
|
-
end
|
195
|
-
|
196
|
-
def test_should_raise_runtime_exception
|
197
|
-
assert_raises(RuntimeError) { invoke(new_expectation.raises) }
|
198
|
-
end
|
199
|
-
|
200
|
-
def test_should_raise_custom_exception
|
201
|
-
exception = Class.new(Exception)
|
202
|
-
assert_raises(exception) { invoke(new_expectation.raises(exception)) }
|
203
|
-
end
|
204
|
-
|
205
|
-
def test_should_raise_same_instance_of_custom_exception
|
206
|
-
exception_klass = Class.new(StandardError)
|
207
|
-
expected_exception = exception_klass.new
|
208
|
-
actual_exception = assert_raises(exception_klass) { invoke(new_expectation.raises(expected_exception)) }
|
209
|
-
assert_same expected_exception, actual_exception
|
210
|
-
end
|
211
|
-
|
212
|
-
def test_should_use_the_default_exception_message
|
213
|
-
exception = assert_raises(Exception) { invoke(new_expectation.raises(Exception)) }
|
214
|
-
assert_equal Exception.new.message, exception.message
|
215
|
-
end
|
216
|
-
|
217
|
-
def test_should_raise_custom_exception_with_message
|
218
|
-
exception_msg = 'exception message'
|
219
|
-
exception = assert_raises(Exception) { invoke(new_expectation.raises(Exception, exception_msg)) }
|
220
|
-
assert_equal exception_msg, exception.message
|
221
|
-
end
|
222
|
-
|
223
|
-
def test_should_return_values_then_raise_exception
|
224
|
-
expectation = new_expectation.returns(1, 2).then.raises
|
225
|
-
assert_equal 1, invoke(expectation)
|
226
|
-
assert_equal 2, invoke(expectation)
|
227
|
-
assert_raises(RuntimeError) { invoke(expectation) }
|
228
|
-
end
|
229
|
-
|
230
|
-
def test_should_raise_exception_then_return_values
|
231
|
-
expectation = new_expectation.raises.then.returns(1, 2)
|
232
|
-
assert_raises(RuntimeError) { invoke(expectation) }
|
233
|
-
assert_equal 1, invoke(expectation)
|
234
|
-
assert_equal 2, invoke(expectation)
|
235
|
-
end
|
236
|
-
|
237
|
-
def test_should_verify_successfully_if_expected_call_was_made
|
238
|
-
expectation = new_expectation
|
239
|
-
invoke(expectation)
|
240
|
-
assert expectation.verified?
|
241
|
-
end
|
242
|
-
|
243
|
-
def test_should_not_verify_successfully_if_call_expected_once_but_invoked_twice
|
244
|
-
expectation = new_expectation.once
|
245
|
-
invoke(expectation)
|
246
|
-
invoke(expectation)
|
247
|
-
assert !expectation.verified?
|
248
|
-
end
|
249
|
-
|
250
|
-
def test_should_not_verify_successfully_if_call_expected_once_but_not_invoked
|
251
|
-
assert !new_expectation.once.verified?
|
252
|
-
end
|
253
|
-
|
254
|
-
def test_should_verify_successfully_if_call_expected_once_and_invoked_once
|
255
|
-
expectation = new_expectation.once
|
256
|
-
invoke(expectation)
|
257
|
-
assert expectation.verified?
|
258
|
-
end
|
259
|
-
|
260
|
-
def test_should_not_verify_successfully_if_call_expected_twice_and_invoked_three_times
|
261
|
-
expectation = new_expectation.twice
|
262
|
-
invoke(expectation)
|
263
|
-
invoke(expectation)
|
264
|
-
invoke(expectation)
|
265
|
-
assert !expectation.verified?
|
266
|
-
end
|
267
|
-
|
268
|
-
def test_should_not_verify_successfully_if_call_expected_twice_but_invoked_once
|
269
|
-
expectation = new_expectation.twice
|
270
|
-
invoke(expectation)
|
271
|
-
assert !expectation.verified?
|
272
|
-
end
|
273
|
-
|
274
|
-
def test_should_verify_successfully_if_call_expected_twice_and_invoked_twice
|
275
|
-
expectation = new_expectation.twice
|
276
|
-
invoke(expectation)
|
277
|
-
invoke(expectation)
|
278
|
-
assert expectation.verified?
|
279
|
-
end
|
280
|
-
|
281
|
-
def test_should_verify_successfully_if_expected_call_was_made_at_least_once
|
282
|
-
expectation = new_expectation.at_least_once
|
283
|
-
3.times { invoke(expectation) }
|
284
|
-
assert expectation.verified?
|
285
|
-
end
|
286
|
-
|
287
|
-
def test_should_not_verify_successfully_if_expected_call_was_not_made_at_least_once
|
288
|
-
expectation = new_expectation.with(1, 2, 3).at_least_once
|
289
|
-
assert !expectation.verified?
|
290
|
-
assert_match(/expected at least once, invoked never/i, expectation.mocha_inspect)
|
291
|
-
end
|
292
|
-
|
293
|
-
def test_should_verify_successfully_if_expected_call_was_made_expected_number_of_times
|
294
|
-
expectation = new_expectation.times(2)
|
295
|
-
2.times { invoke(expectation) }
|
296
|
-
assert expectation.verified?
|
297
|
-
end
|
298
|
-
|
299
|
-
def test_should_not_verify_successfully_if_expected_call_was_made_too_few_times
|
300
|
-
expectation = new_expectation.times(2)
|
301
|
-
1.times { invoke(expectation) }
|
302
|
-
assert !expectation.verified?
|
303
|
-
assert_match(/expected exactly twice, invoked once/i, expectation.mocha_inspect)
|
304
|
-
end
|
305
|
-
|
306
|
-
def test_should_not_verify_successfully_if_expected_call_was_made_too_many_times
|
307
|
-
expectation = new_expectation.times(2)
|
308
|
-
3.times { invoke(expectation) }
|
309
|
-
assert !expectation.verified?
|
310
|
-
end
|
311
|
-
|
312
|
-
def test_should_increment_assertion_counter_for_expectation_because_it_does_need_verifyng
|
313
|
-
expectation = new_expectation
|
314
|
-
invoke(expectation)
|
315
|
-
assertion_counter = SimpleCounter.new
|
316
|
-
expectation.verified?(assertion_counter)
|
317
|
-
assert_equal 1, assertion_counter.count
|
318
|
-
end
|
319
|
-
|
320
|
-
def test_should_not_increment_assertion_counter_for_stub_because_it_does_not_need_verifying
|
321
|
-
assertion_counter = SimpleCounter.new
|
322
|
-
Expectation.new(nil, :expected_method).at_least(0).verified?(assertion_counter)
|
323
|
-
assert_equal 0, assertion_counter.count
|
324
|
-
end
|
325
|
-
|
326
|
-
# rubocop:disable Style/Semicolon
|
327
|
-
def test_should_store_backtrace_from_point_where_expectation_was_created
|
328
|
-
execution_point = ExecutionPoint.current; expectation = Expectation.new(nil, :expected_method)
|
329
|
-
assert_equal execution_point, ExecutionPoint.new(expectation.backtrace)
|
330
|
-
end
|
331
|
-
# rubocop:enable Style/Semicolon
|
332
|
-
|
333
|
-
class FakeMock
|
334
|
-
def initialize(name)
|
335
|
-
@name = name
|
336
|
-
end
|
337
|
-
|
338
|
-
def mocha_inspect
|
339
|
-
@name
|
340
|
-
end
|
341
|
-
end
|
342
|
-
|
343
|
-
def test_should_raise_error_with_message_indicating_which_method_was_expected_to_be_called_on_which_mock_object_with_which_parameters_and_in_what_sequences
|
344
|
-
mock = FakeMock.new('mock')
|
345
|
-
sequence_one = Sequence.new('one')
|
346
|
-
sequence_two = Sequence.new('two')
|
347
|
-
expectation = Expectation.new(mock, :expected_method).with(1, 2, { 'a' => true }, { :b => false }, [1, 2, 3]).in_sequence(sequence_one, sequence_two)
|
348
|
-
assert !expectation.verified?
|
349
|
-
assert_match %{mock.expected_method(1, 2, {"a" => true}, {:b => false}, [1, 2, 3]); in sequence "one"; in sequence "two"}, expectation.mocha_inspect
|
350
|
-
end
|
351
|
-
|
352
|
-
class FakeConstraint
|
353
|
-
def initialize(allows_invocation_now)
|
354
|
-
@allows_invocation_now = allows_invocation_now
|
355
|
-
end
|
356
|
-
|
357
|
-
def allows_invocation_now?
|
358
|
-
@allows_invocation_now
|
359
|
-
end
|
360
|
-
end
|
361
|
-
|
362
|
-
def test_should_be_in_correct_order_if_all_ordering_constraints_allow_invocation_now
|
363
|
-
constraint_one = FakeConstraint.new(true)
|
364
|
-
constraint_two = FakeConstraint.new(true)
|
365
|
-
expectation = Expectation.new(nil, :method_one)
|
366
|
-
expectation.add_ordering_constraint(constraint_one)
|
367
|
-
expectation.add_ordering_constraint(constraint_two)
|
368
|
-
assert expectation.in_correct_order?
|
369
|
-
end
|
370
|
-
|
371
|
-
def test_should_not_be_in_correct_order_if_one_ordering_constraint_does_not_allow_invocation_now
|
372
|
-
constraint_one = FakeConstraint.new(true)
|
373
|
-
constraint_two = FakeConstraint.new(false)
|
374
|
-
expectation = Expectation.new(nil, :method_one)
|
375
|
-
expectation.add_ordering_constraint(constraint_one)
|
376
|
-
expectation.add_ordering_constraint(constraint_two)
|
377
|
-
assert !expectation.in_correct_order?
|
378
|
-
end
|
379
|
-
|
380
|
-
def test_should_match_if_all_ordering_constraints_allow_invocation_now
|
381
|
-
constraint_one = FakeConstraint.new(true)
|
382
|
-
constraint_two = FakeConstraint.new(true)
|
383
|
-
expectation = Expectation.new(nil, :method_one)
|
384
|
-
expectation.add_ordering_constraint(constraint_one)
|
385
|
-
expectation.add_ordering_constraint(constraint_two)
|
386
|
-
assert expectation.match?(Invocation.new(:irrelevant, :method_one))
|
387
|
-
end
|
388
|
-
|
389
|
-
def test_should_not_match_if_one_ordering_constraints_does_not_allow_invocation_now
|
390
|
-
constraint_one = FakeConstraint.new(true)
|
391
|
-
constraint_two = FakeConstraint.new(false)
|
392
|
-
expectation = Expectation.new(nil, :method_one)
|
393
|
-
expectation.add_ordering_constraint(constraint_one)
|
394
|
-
expectation.add_ordering_constraint(constraint_two)
|
395
|
-
assert !expectation.match?(Invocation.new(:irrelevant, :method_one))
|
396
|
-
end
|
397
|
-
|
398
|
-
def test_should_not_be_satisfied_when_required_invocation_has_not_been_made
|
399
|
-
assert !Expectation.new(nil, :method_one).times(1).satisfied?
|
400
|
-
end
|
401
|
-
|
402
|
-
def test_should_be_satisfied_when_required_invocation_has_been_made
|
403
|
-
expectation = Expectation.new(nil, :method_one).times(1)
|
404
|
-
invoke(expectation)
|
405
|
-
assert expectation.satisfied?
|
406
|
-
end
|
407
|
-
|
408
|
-
def test_should_not_be_satisfied_when_minimum_number_of_invocations_has_not_been_made
|
409
|
-
expectation = Expectation.new(nil, :method_one).at_least(2)
|
410
|
-
invoke(expectation)
|
411
|
-
assert !expectation.satisfied?
|
412
|
-
end
|
413
|
-
|
414
|
-
def test_should_be_satisfied_when_minimum_number_of_invocations_has_been_made
|
415
|
-
expectation = Expectation.new(nil, :method_one).at_least(2)
|
416
|
-
2.times { invoke(expectation) }
|
417
|
-
assert expectation.satisfied?
|
418
|
-
end
|
419
|
-
|
420
|
-
class FakeSequence
|
421
|
-
attr_reader :expectations
|
422
|
-
|
423
|
-
def initialize
|
424
|
-
@expectations = []
|
425
|
-
end
|
426
|
-
|
427
|
-
def constrain_as_next_in_sequence(expectation)
|
428
|
-
@expectations << expectation
|
429
|
-
end
|
430
|
-
end
|
431
|
-
|
432
|
-
def test_should_tell_sequences_to_constrain_expectation_as_next_in_sequence
|
433
|
-
sequence_one = FakeSequence.new
|
434
|
-
sequence_two = FakeSequence.new
|
435
|
-
expectation = Expectation.new(nil, :method_one)
|
436
|
-
assert_equal expectation, expectation.in_sequence(sequence_one, sequence_two)
|
437
|
-
assert_equal [expectation], sequence_one.expectations
|
438
|
-
assert_equal [expectation], sequence_two.expectations
|
439
|
-
end
|
440
|
-
|
441
|
-
class FakeState
|
442
|
-
def initialize
|
443
|
-
@active = false
|
444
|
-
end
|
445
|
-
|
446
|
-
def activate
|
447
|
-
@active = true
|
448
|
-
end
|
449
|
-
|
450
|
-
def active?
|
451
|
-
@active
|
452
|
-
end
|
453
|
-
end
|
454
|
-
|
455
|
-
def test_should_change_state_when_expectation_is_invoked
|
456
|
-
state = FakeState.new
|
457
|
-
expectation = Expectation.new(nil, :method_one)
|
458
|
-
|
459
|
-
expectation.then(state)
|
460
|
-
|
461
|
-
invoke(expectation)
|
462
|
-
assert state.active?
|
463
|
-
end
|
464
|
-
|
465
|
-
def test_should_match_when_state_is_active
|
466
|
-
state = FakeState.new
|
467
|
-
expectation = Expectation.new(nil, :method_one)
|
468
|
-
|
469
|
-
expectation.when(state)
|
470
|
-
assert !expectation.match?(Invocation.new(:irrelevant, :method_one))
|
471
|
-
|
472
|
-
state.activate
|
473
|
-
assert expectation.match?(Invocation.new(:irrelevant, :method_one))
|
474
|
-
end
|
475
|
-
|
476
|
-
def test_should_include_default_representation_of_object_in_inspect
|
477
|
-
object = Object.new
|
478
|
-
class << object
|
479
|
-
define_method(:inspect) { 'mock' }
|
480
|
-
end
|
481
|
-
assert_match Regexp.new('^#<Expectation:0x[0-9A-Fa-f]{1,12} .* >$'), Expectation.new(object, :method_one).inspect
|
482
|
-
end
|
483
|
-
|
484
|
-
def test_should_include_output_of_mocha_inspect_in_inspect
|
485
|
-
object = Object.new
|
486
|
-
class << object
|
487
|
-
define_method(:inspect) { 'mock' }
|
488
|
-
end
|
489
|
-
expectation = Expectation.new(object, :method_one)
|
490
|
-
assert expectation.inspect.include?(expectation.mocha_inspect)
|
491
|
-
end
|
492
|
-
end
|