mocha 1.11.2 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +5 -1
- data/CONTRIBUTING.md +1 -1
- data/Gemfile +29 -0
- data/README.md +35 -31
- data/RELEASE.md +128 -0
- data/Rakefile +26 -22
- data/gemfiles/Gemfile.minitest.latest +1 -0
- data/gemfiles/Gemfile.test-unit.latest +2 -5
- data/lib/mocha/any_instance_method.rb +0 -5
- data/lib/mocha/api.rb +29 -78
- data/lib/mocha/cardinality.rb +30 -27
- data/lib/mocha/class_methods.rb +2 -2
- data/lib/mocha/configuration.rb +30 -108
- data/lib/mocha/expectation.rb +86 -31
- data/lib/mocha/inspect.rb +5 -3
- data/lib/mocha/instance_method.rb +0 -4
- data/lib/mocha/integration/mini_test.rb +10 -38
- data/lib/mocha/integration/test_unit/adapter.rb +1 -1
- data/lib/mocha/integration/test_unit.rb +10 -33
- data/lib/mocha/invocation.rb +12 -16
- data/lib/mocha/minitest.rb +2 -4
- data/lib/mocha/mock.rb +26 -26
- data/lib/mocha/mockery.rb +10 -25
- data/lib/mocha/parameter_matchers/base.rb +1 -1
- data/lib/mocha/parameter_matchers/equivalent_uri.rb +0 -1
- data/lib/mocha/parameter_matchers/has_entry.rb +22 -13
- data/lib/mocha/parameter_matchers/has_keys.rb +53 -0
- data/lib/mocha/parameter_matchers/instance_methods.rb +10 -1
- data/lib/mocha/parameter_matchers/positional_or_keyword_hash.rb +64 -0
- data/lib/mocha/parameter_matchers.rb +1 -0
- data/lib/mocha/parameters_matcher.rb +3 -3
- data/lib/mocha/ruby_version.rb +1 -2
- data/lib/mocha/state_machine.rb +30 -38
- data/lib/mocha/stubbed_method.rb +5 -42
- data/lib/mocha/test_unit.rb +2 -4
- data/lib/mocha/version.rb +1 -1
- data/lib/mocha.rb +0 -8
- data/mocha.gemspec +6 -31
- metadata +10 -286
- data/bin/build-matrix +0 -82
- data/docs/CNAME +0 -1
- data/docs/Mocha/API.html +0 -1285
- data/docs/Mocha/ClassMethods.html +0 -264
- data/docs/Mocha/Configuration.html +0 -1525
- data/docs/Mocha/Expectation.html +0 -2862
- data/docs/Mocha/ExpectationError.html +0 -152
- data/docs/Mocha/ExpectationErrorFactory.html +0 -260
- data/docs/Mocha/Hooks.html +0 -370
- data/docs/Mocha/Integration/MiniTest/Adapter.html +0 -164
- data/docs/Mocha/Integration/MiniTest.html +0 -123
- data/docs/Mocha/Integration/TestUnit/Adapter.html +0 -164
- data/docs/Mocha/Integration/TestUnit.html +0 -123
- data/docs/Mocha/Integration.html +0 -125
- data/docs/Mocha/Mock.html +0 -1210
- data/docs/Mocha/ObjectMethods.html +0 -765
- 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/ParameterMatchers.html +0 -2949
- data/docs/Mocha/Sequence.html +0 -149
- data/docs/Mocha/StateMachine/State.html +0 -140
- data/docs/Mocha/StateMachine/StatePredicate.html +0 -140
- data/docs/Mocha/StateMachine.html +0 -527
- data/docs/Mocha/StubbingError.html +0 -150
- data/docs/Mocha.html +0 -254
- data/docs/_index.html +0 -519
- data/docs/class_list.html +0 -51
- data/docs/css/common.css +0 -1
- data/docs/css/full_list.css +0 -58
- data/docs/css/style.css +0 -496
- data/docs/file.COPYING.html +0 -81
- data/docs/file.MIT-LICENSE.html +0 -85
- data/docs/file.README.html +0 -448
- data/docs/file.RELEASE.html +0 -1028
- data/docs/file_list.html +0 -71
- data/docs/frames.html +0 -17
- data/docs/index.html +0 -448
- data/docs/js/app.js +0 -303
- data/docs/js/full_list.js +0 -216
- data/docs/js/jquery.js +0 -4
- data/docs/method_list.html +0 -651
- data/docs/top-level-namespace.html +0 -118
- data/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/init.rb +0 -1
- data/lib/mocha/integration/mini_test/nothing.rb +0 -19
- data/lib/mocha/integration/mini_test/version_13.rb +0 -54
- data/lib/mocha/integration/mini_test/version_140.rb +0 -54
- data/lib/mocha/integration/mini_test/version_141.rb +0 -65
- data/lib/mocha/integration/mini_test/version_142_to_172.rb +0 -65
- data/lib/mocha/integration/mini_test/version_200.rb +0 -66
- data/lib/mocha/integration/mini_test/version_201_to_222.rb +0 -66
- data/lib/mocha/integration/mini_test/version_2110_to_2111.rb +0 -70
- data/lib/mocha/integration/mini_test/version_2112_to_320.rb +0 -73
- data/lib/mocha/integration/mini_test/version_230_to_2101.rb +0 -68
- data/lib/mocha/integration/test_unit/gem_version_200.rb +0 -62
- data/lib/mocha/integration/test_unit/gem_version_201_to_202.rb +0 -62
- data/lib/mocha/integration/test_unit/gem_version_203_to_220.rb +0 -62
- data/lib/mocha/integration/test_unit/gem_version_230_to_250.rb +0 -68
- data/lib/mocha/integration/test_unit/nothing.rb +0 -19
- data/lib/mocha/integration/test_unit/ruby_version_185_and_below.rb +0 -61
- data/lib/mocha/integration/test_unit/ruby_version_186_and_above.rb +0 -63
- data/lib/mocha/integration.rb +0 -11
- data/lib/mocha/setup.rb +0 -14
- data/lib/mocha/singleton_class.rb +0 -9
- data/test/acceptance/acceptance_test_helper.rb +0 -42
- data/test/acceptance/bug_18914_test.rb +0 -37
- data/test/acceptance/bug_21465_test.rb +0 -31
- data/test/acceptance/bug_21563_test.rb +0 -22
- data/test/acceptance/display_matching_invocations_alongside_expectations_test.rb +0 -69
- data/test/acceptance/exception_rescue_test.rb +0 -53
- data/test/acceptance/expectations_on_multiple_methods_test.rb +0 -55
- data/test/acceptance/expected_invocation_count_test.rb +0 -229
- data/test/acceptance/failure_messages_test.rb +0 -77
- data/test/acceptance/issue_272_test.rb +0 -50
- data/test/acceptance/issue_457_test.rb +0 -31
- data/test/acceptance/issue_65_test.rb +0 -64
- data/test/acceptance/issue_70_test.rb +0 -53
- data/test/acceptance/mocha_example_test.rb +0 -106
- data/test/acceptance/mocha_test_result_test.rb +0 -83
- data/test/acceptance/mock_built_with_first_argument_type_being_string_test.rb +0 -98
- data/test/acceptance/mock_test.rb +0 -191
- data/test/acceptance/mocked_methods_dispatch_test.rb +0 -75
- data/test/acceptance/multiple_expectations_failure_message_test.rb +0 -66
- data/test/acceptance/multiple_yielding_test.rb +0 -59
- data/test/acceptance/optional_parameters_test.rb +0 -67
- data/test/acceptance/parameter_matcher_test.rb +0 -299
- data/test/acceptance/partial_mocks_test.rb +0 -44
- data/test/acceptance/prepend_test.rb +0 -86
- data/test/acceptance/prevent_use_of_mocha_outside_test_test.rb +0 -76
- data/test/acceptance/raise_exception_test.rb +0 -36
- data/test/acceptance/return_value_test.rb +0 -49
- data/test/acceptance/sequence_test.rb +0 -189
- data/test/acceptance/states_test.rb +0 -71
- data/test/acceptance/stub_any_instance_method_defined_on_superclass_test.rb +0 -64
- data/test/acceptance/stub_any_instance_method_test.rb +0 -301
- data/test/acceptance/stub_class_method_defined_on_active_record_association_proxy_test.rb +0 -105
- data/test/acceptance/stub_class_method_defined_on_class_test.rb +0 -78
- data/test/acceptance/stub_class_method_defined_on_module_test.rb +0 -73
- data/test/acceptance/stub_class_method_defined_on_superclass_test.rb +0 -144
- data/test/acceptance/stub_everything_test.rb +0 -53
- data/test/acceptance/stub_instance_method_defined_on_active_record_association_proxy_test.rb +0 -91
- data/test/acceptance/stub_instance_method_defined_on_class_and_aliased_test.rb +0 -67
- data/test/acceptance/stub_instance_method_defined_on_class_test.rb +0 -67
- data/test/acceptance/stub_instance_method_defined_on_kernel_module_test.rb +0 -136
- data/test/acceptance/stub_instance_method_defined_on_module_test.rb +0 -76
- data/test/acceptance/stub_instance_method_defined_on_object_class_test.rb +0 -75
- data/test/acceptance/stub_instance_method_defined_on_singleton_class_test.rb +0 -67
- data/test/acceptance/stub_instance_method_defined_on_superclass_test.rb +0 -70
- data/test/acceptance/stub_method_defined_on_module_and_aliased_test.rb +0 -38
- data/test/acceptance/stub_module_method_test.rb +0 -200
- data/test/acceptance/stub_test.rb +0 -49
- data/test/acceptance/stubba_example_test.rb +0 -103
- data/test/acceptance/stubba_test_result_test.rb +0 -71
- data/test/acceptance/stubbing_error_backtrace_test.rb +0 -63
- data/test/acceptance/stubbing_frozen_object_test.rb +0 -88
- data/test/acceptance/stubbing_method_accepting_block_parameter_test.rb +0 -52
- data/test/acceptance/stubbing_method_unnecessarily_test.rb +0 -63
- data/test/acceptance/stubbing_nil_test.rb +0 -60
- data/test/acceptance/stubbing_non_existent_any_instance_method_test.rb +0 -157
- data/test/acceptance/stubbing_non_existent_class_method_test.rb +0 -157
- data/test/acceptance/stubbing_non_existent_instance_method_test.rb +0 -145
- data/test/acceptance/stubbing_non_public_any_instance_method_test.rb +0 -128
- data/test/acceptance/stubbing_non_public_class_method_test.rb +0 -163
- data/test/acceptance/stubbing_non_public_instance_method_test.rb +0 -141
- data/test/acceptance/stubbing_on_non_mock_object_test.rb +0 -70
- data/test/acceptance/stubbing_same_class_method_on_parent_and_child_classes_test.rb +0 -33
- data/test/acceptance/throw_test.rb +0 -42
- data/test/acceptance/unexpected_invocation_test.rb +0 -23
- data/test/acceptance/unstubbing_test.rb +0 -194
- data/test/acceptance/yielding_test.rb +0 -80
- data/test/assertions.rb +0 -8
- data/test/deprecation_disabler.rb +0 -15
- data/test/execution_point.rb +0 -36
- data/test/integration/mini_test_test.rb +0 -8
- data/test/integration/shared_tests.rb +0 -178
- data/test/integration/test_unit_test.rb +0 -8
- data/test/method_definer.rb +0 -16
- data/test/mini_test_result.rb +0 -96
- data/test/minitest_result.rb +0 -48
- data/test/simple_counter.rb +0 -11
- data/test/test_helper.rb +0 -58
- data/test/test_runner.rb +0 -58
- data/test/test_unit_result.rb +0 -22
- data/test/unit/any_instance_method_test.rb +0 -175
- data/test/unit/array_inspect_test.rb +0 -14
- data/test/unit/backtrace_filter_test.rb +0 -17
- data/test/unit/cardinality_test.rb +0 -72
- data/test/unit/central_test.rb +0 -98
- data/test/unit/change_state_side_effect_test.rb +0 -37
- data/test/unit/class_methods_test.rb +0 -69
- data/test/unit/configuration_test.rb +0 -37
- data/test/unit/date_time_inspect_test.rb +0 -19
- data/test/unit/exception_raiser_test.rb +0 -45
- data/test/unit/expectation_list_test.rb +0 -82
- data/test/unit/expectation_test.rb +0 -504
- data/test/unit/hash_inspect_test.rb +0 -14
- data/test/unit/hooks_test.rb +0 -35
- data/test/unit/in_state_ordering_constraint_test.rb +0 -39
- data/test/unit/instance_method_test.rb +0 -282
- data/test/unit/method_matcher_test.rb +0 -26
- data/test/unit/mock_test.rb +0 -372
- data/test/unit/mockery_test.rb +0 -171
- data/test/unit/module_methods_test.rb +0 -16
- data/test/unit/object_inspect_test.rb +0 -60
- data/test/unit/object_methods_test.rb +0 -63
- data/test/unit/parameter_matchers/all_of_test.rb +0 -24
- data/test/unit/parameter_matchers/any_of_test.rb +0 -24
- data/test/unit/parameter_matchers/anything_test.rb +0 -19
- data/test/unit/parameter_matchers/equals_test.rb +0 -23
- data/test/unit/parameter_matchers/equivalent_uri_test.rb +0 -41
- data/test/unit/parameter_matchers/has_entries_test.rb +0 -51
- data/test/unit/parameter_matchers/has_entry_test.rb +0 -128
- data/test/unit/parameter_matchers/has_key_test.rb +0 -54
- data/test/unit/parameter_matchers/has_value_test.rb +0 -55
- data/test/unit/parameter_matchers/includes_test.rb +0 -106
- data/test/unit/parameter_matchers/instance_of_test.rb +0 -23
- data/test/unit/parameter_matchers/is_a_test.rb +0 -23
- data/test/unit/parameter_matchers/kind_of_test.rb +0 -23
- data/test/unit/parameter_matchers/not_test.rb +0 -24
- data/test/unit/parameter_matchers/regexp_matches_test.rb +0 -45
- data/test/unit/parameter_matchers/responds_with_test.rb +0 -38
- data/test/unit/parameter_matchers/stub_matcher.rb +0 -23
- data/test/unit/parameter_matchers/yaml_equivalent_test.rb +0 -23
- data/test/unit/parameters_matcher_test.rb +0 -119
- data/test/unit/receivers_test.rb +0 -96
- data/test/unit/return_values_test.rb +0 -66
- data/test/unit/sequence_test.rb +0 -100
- data/test/unit/single_return_value_test.rb +0 -17
- data/test/unit/state_machine_test.rb +0 -96
- data/test/unit/string_inspect_test.rb +0 -9
- data/test/unit/thrower_test.rb +0 -23
- data/test/unit/yield_parameters_test.rb +0 -73
data/lib/mocha/cardinality.rb
CHANGED
@@ -2,31 +2,28 @@ module Mocha
|
|
2
2
|
class Cardinality
|
3
3
|
INFINITY = 1 / 0.0
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
def initialize(required = 0, maximum = INFINITY)
|
6
|
+
update(required, maximum)
|
7
|
+
@invocations = []
|
8
|
+
end
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
def exactly(count)
|
11
|
+
update(count, count)
|
12
|
+
end
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
def at_least(count)
|
15
|
+
update(count, INFINITY)
|
16
|
+
end
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
when Range then new(range_or_count.first, range_or_count.last)
|
21
|
-
else new(range_or_count, range_or_count)
|
22
|
-
end
|
23
|
-
end
|
18
|
+
def at_most(count)
|
19
|
+
update(0, count)
|
24
20
|
end
|
25
21
|
|
26
|
-
def
|
27
|
-
|
28
|
-
|
29
|
-
|
22
|
+
def times(range_or_count)
|
23
|
+
case range_or_count
|
24
|
+
when Range then update(range_or_count.first, range_or_count.last)
|
25
|
+
else update(range_or_count, range_or_count)
|
26
|
+
end
|
30
27
|
end
|
31
28
|
|
32
29
|
def <<(invocation)
|
@@ -62,21 +59,21 @@ module Mocha
|
|
62
59
|
if allowed_any_number_of_times?
|
63
60
|
'allowed any number of times'
|
64
61
|
elsif required.zero? && maximum.zero?
|
65
|
-
"expected #{
|
62
|
+
"expected #{count(maximum)}"
|
66
63
|
elsif required == maximum
|
67
|
-
"expected exactly #{
|
64
|
+
"expected exactly #{count(required)}"
|
68
65
|
elsif infinite?(maximum)
|
69
|
-
"expected at least #{
|
66
|
+
"expected at least #{count(required)}"
|
70
67
|
elsif required.zero?
|
71
|
-
"expected at most #{
|
68
|
+
"expected at most #{count(maximum)}"
|
72
69
|
else
|
73
|
-
"expected between #{required} and #{
|
70
|
+
"expected between #{required} and #{count(maximum)}"
|
74
71
|
end
|
75
72
|
end
|
76
73
|
# rubocop:enable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
|
77
74
|
|
78
75
|
def invoked_times
|
79
|
-
"invoked #{
|
76
|
+
"invoked #{count(@invocations.size)}"
|
80
77
|
end
|
81
78
|
|
82
79
|
def actual_invocations
|
@@ -87,7 +84,7 @@ module Mocha
|
|
87
84
|
|
88
85
|
attr_reader :required, :maximum
|
89
86
|
|
90
|
-
def
|
87
|
+
def count(number)
|
91
88
|
case number
|
92
89
|
when 0 then 'never'
|
93
90
|
when 1 then 'once'
|
@@ -96,6 +93,12 @@ module Mocha
|
|
96
93
|
end
|
97
94
|
end
|
98
95
|
|
96
|
+
def update(required, maximum)
|
97
|
+
@required = required
|
98
|
+
@maximum = maximum
|
99
|
+
self
|
100
|
+
end
|
101
|
+
|
99
102
|
def infinite?(number)
|
100
103
|
number.respond_to?(:infinite?) && number.infinite?
|
101
104
|
end
|
data/lib/mocha/class_methods.rb
CHANGED
@@ -26,8 +26,8 @@ module Mocha
|
|
26
26
|
@stubba_object
|
27
27
|
end
|
28
28
|
|
29
|
-
def respond_to?(
|
30
|
-
@stubba_object.allocate.respond_to?(
|
29
|
+
def respond_to?(symbol, include_all = false)
|
30
|
+
@stubba_object.allocate.respond_to?(symbol.to_sym, include_all)
|
31
31
|
end
|
32
32
|
|
33
33
|
attr_reader :stubba_object
|
data/lib/mocha/configuration.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'mocha/ruby_version'
|
2
|
+
|
1
3
|
module Mocha
|
2
4
|
# Allows setting of configuration options. See {Configuration} for the available options.
|
3
5
|
#
|
@@ -43,7 +45,7 @@ module Mocha
|
|
43
45
|
:stubbing_non_public_method => :allow,
|
44
46
|
:stubbing_method_on_nil => :prevent,
|
45
47
|
:display_matching_invocations_on_failure => false,
|
46
|
-
:
|
48
|
+
:strict_keyword_argument_matching => false
|
47
49
|
}.freeze
|
48
50
|
|
49
51
|
attr_reader :options
|
@@ -248,134 +250,54 @@ module Mocha
|
|
248
250
|
@options[:display_matching_invocations_on_failure]
|
249
251
|
end
|
250
252
|
|
251
|
-
#
|
252
|
-
#
|
253
|
-
# Previously when {API#mock}, {API#stub}, or {API#stub_everything} were called with the first argument being a symbol, they built an *unnamed* mock object *and* expected or stubbed the method identified by the symbol argument; subsequent arguments were ignored.
|
254
|
-
# Now these methods build a *named* mock with the name specified by the symbol argument; *no* methods are expected or stubbed and subsequent arguments *are* taken into account.
|
253
|
+
# Perform strict keyword argument comparison. Only supported in Ruby >= v2.7.
|
255
254
|
#
|
256
|
-
#
|
257
|
-
# Now a +LocalJumpError+ is raised.
|
255
|
+
# When this option is set to +false+ a positional +Hash+ and a set of keyword arguments are treated the same during comparison, which can lead to misleading passing tests in Ruby >= v3.0 (see examples below). However, a deprecation warning will be displayed if a positional +Hash+ matches a set of keyword arguments or vice versa. This is because {#strict_keyword_argument_matching=} will default to +true+ in the future.
|
258
256
|
#
|
259
|
-
#
|
257
|
+
# For more details on keyword arguments in Ruby v3, refer to {https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0 this article}.
|
260
258
|
#
|
261
|
-
#
|
259
|
+
# Note that +Hash+-related matchers such as {ParameterMatchers#has_value} or {ParameterMatchers#has_key} will still treat a positional +Hash+ and a set of keyword arguments the same, so misleading passing tests are still possible when they are used.
|
262
260
|
#
|
263
|
-
#
|
264
|
-
# Mocha.configure do |c|
|
265
|
-
# c.reinstate_undocumented_behaviour_from_v1_9 = true
|
266
|
-
# end
|
261
|
+
# This configuration option is +false+ by default to enable gradual adoption, but will be +true+ by default in the future.
|
267
262
|
#
|
268
|
-
#
|
269
|
-
# foo.inspect # => #<Mock>
|
263
|
+
# @param [Boolean] value +true+ to enable strict keyword argument matching; +false+ by default.
|
270
264
|
#
|
271
|
-
#
|
272
|
-
# unsatisfied expectations:
|
273
|
-
# - expected exactly once, invoked never: #<Mock>.foo
|
265
|
+
# @example Loose keyword argument matching (default)
|
274
266
|
#
|
275
|
-
#
|
276
|
-
#
|
277
|
-
# c.reinstate_undocumented_behaviour_from_v1_9 = true
|
267
|
+
# class Example
|
268
|
+
# def foo(a, bar:); end
|
278
269
|
# end
|
279
270
|
#
|
280
|
-
#
|
281
|
-
# foo.
|
282
|
-
# foo
|
271
|
+
# example = Example.new
|
272
|
+
# example.expects(:foo).with('a', bar: 'b')
|
273
|
+
# example.foo('a', { bar: 'b' })
|
274
|
+
# # This passes the test, but would result in an ArgumentError in practice
|
283
275
|
#
|
284
|
-
# @example
|
285
|
-
# foo = mock('foo')
|
286
|
-
# foo.stubs(:my_method).yields(1, 2)
|
287
|
-
# foo.my_method # => raises LocalJumpError when no block is supplied
|
276
|
+
# @example Strict keyword argument matching
|
288
277
|
#
|
289
278
|
# Mocha.configure do |c|
|
290
|
-
# c.
|
279
|
+
# c.strict_keyword_argument_matching = true
|
291
280
|
# end
|
292
281
|
#
|
293
|
-
#
|
294
|
-
#
|
295
|
-
#
|
282
|
+
# class Example
|
283
|
+
# def foo(a, bar:); end
|
284
|
+
# end
|
296
285
|
#
|
297
|
-
|
298
|
-
|
286
|
+
# example = Example.new
|
287
|
+
# example.expects(:foo).with('a', bar: 'b')
|
288
|
+
# example.foo('a', { bar: 'b' })
|
289
|
+
# # This now fails as expected
|
290
|
+
def strict_keyword_argument_matching=(value)
|
291
|
+
raise 'Strict keyword argument matching requires Ruby 2.7 and above.' unless Mocha::RUBY_V27_PLUS
|
292
|
+
@options[:strict_keyword_argument_matching] = value
|
299
293
|
end
|
300
294
|
|
301
295
|
# @private
|
302
|
-
def
|
303
|
-
@options[:
|
296
|
+
def strict_keyword_argument_matching?
|
297
|
+
@options[:strict_keyword_argument_matching]
|
304
298
|
end
|
305
299
|
|
306
300
|
class << self
|
307
|
-
# Allow the specified +action+.
|
308
|
-
#
|
309
|
-
# @param [Symbol] action one of +:stubbing_method_unnecessarily+, +:stubbing_method_on_non_mock_object+, +:stubbing_non_existent_method+, +:stubbing_non_public_method+, +:stubbing_method_on_nil+.
|
310
|
-
# @yield optional block during which the configuration change will be changed before being returned to its original value at the end of the block.
|
311
|
-
# @deprecated If a block is supplied, call {.override} with a +Hash+ containing an entry with the +action+ as the key and +:allow+ as the value. If no block is supplied, call the appropriate +action+ writer method with +value+ set to +:allow+ via {Mocha.configure}. The writer method will be the one of the following corresponding to the +action+:
|
312
|
-
# * {#stubbing_method_unnecessarily=}
|
313
|
-
# * {#stubbing_method_on_non_mock_object=}
|
314
|
-
# * {#stubbing_non_existent_method=}
|
315
|
-
# * {#stubbing_non_public_method=}
|
316
|
-
# * {#stubbing_method_on_nil=}
|
317
|
-
def allow(action, &block)
|
318
|
-
if block_given?
|
319
|
-
Deprecation.warning("Use Mocha::Configuration.override(#{action}: :allow) with the same block")
|
320
|
-
else
|
321
|
-
Deprecation.warning("Use Mocha.configure { |c| c.#{action} = :allow }")
|
322
|
-
end
|
323
|
-
change_config action, :allow, &block
|
324
|
-
end
|
325
|
-
|
326
|
-
# @private
|
327
|
-
def allow?(action)
|
328
|
-
configuration.allow?(action)
|
329
|
-
end
|
330
|
-
|
331
|
-
# Warn if the specified +action+ is attempted.
|
332
|
-
#
|
333
|
-
# @param [Symbol] action one of +:stubbing_method_unnecessarily+, +:stubbing_method_on_non_mock_object+, +:stubbing_non_existent_method+, +:stubbing_non_public_method+, +:stubbing_method_on_nil+.
|
334
|
-
# @yield optional block during which the configuration change will be changed before being returned to its original value at the end of the block.
|
335
|
-
# @deprecated If a block is supplied, call {.override} with a +Hash+ containing an entry with the +action+ as the key and +:warn+ as the value. If no block is supplied, call the appropriate +action+ writer method with +value+ set to +:warn+ via {Mocha.configure}. The writer method will be the one of the following corresponding to the +action+:
|
336
|
-
# * {#stubbing_method_unnecessarily=}
|
337
|
-
# * {#stubbing_method_on_non_mock_object=}
|
338
|
-
# * {#stubbing_non_existent_method=}
|
339
|
-
# * {#stubbing_non_public_method=}
|
340
|
-
# * {#stubbing_method_on_nil=}
|
341
|
-
def warn_when(action, &block)
|
342
|
-
if block_given?
|
343
|
-
Deprecation.warning("Use Mocha::Configuration.override(#{action}: :warn) with the same block")
|
344
|
-
else
|
345
|
-
Deprecation.warning("Use Mocha.configure { |c| c.#{action} = :warn }")
|
346
|
-
end
|
347
|
-
change_config action, :warn, &block
|
348
|
-
end
|
349
|
-
|
350
|
-
# @private
|
351
|
-
def warn_when?(action)
|
352
|
-
configuration.warn_when?(action)
|
353
|
-
end
|
354
|
-
|
355
|
-
# Raise a {StubbingError} if the specified +action+ is attempted.
|
356
|
-
#
|
357
|
-
# @param [Symbol] action one of +:stubbing_method_unnecessarily+, +:stubbing_method_on_non_mock_object+, +:stubbing_non_existent_method+, +:stubbing_non_public_method+, +:stubbing_method_on_nil+.
|
358
|
-
# @yield optional block during which the configuration change will be changed before being returned to its original value at the end of the block.
|
359
|
-
# @deprecated If a block is supplied, call {.override} with a +Hash+ containing an entry with the +action+ as the key and +:prevent+ as the value. If no block is supplied, call the appropriate +action+ writer method with +value+ set to +:prevent+ via {Mocha.configure}. The writer method will be the one of the following corresponding to the +action+:
|
360
|
-
# * {#stubbing_method_unnecessarily=}
|
361
|
-
# * {#stubbing_method_on_non_mock_object=}
|
362
|
-
# * {#stubbing_non_existent_method=}
|
363
|
-
# * {#stubbing_non_public_method=}
|
364
|
-
# * {#stubbing_method_on_nil=}
|
365
|
-
def prevent(action, &block)
|
366
|
-
if block_given?
|
367
|
-
Deprecation.warning("Use Mocha::Configuration.override(#{action}: :prevent) with the same block")
|
368
|
-
else
|
369
|
-
Deprecation.warning("Use Mocha.configure { |c| c.#{action} = :prevent }")
|
370
|
-
end
|
371
|
-
change_config action, :prevent, &block
|
372
|
-
end
|
373
|
-
|
374
|
-
# @private
|
375
|
-
def prevent?(action)
|
376
|
-
configuration.prevent?(action)
|
377
|
-
end
|
378
|
-
|
379
301
|
# @private
|
380
302
|
def reset_configuration
|
381
303
|
@configuration = nil
|
data/lib/mocha/expectation.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'ruby2_keywords'
|
1
2
|
require 'mocha/method_matcher'
|
2
3
|
require 'mocha/parameters_matcher'
|
3
4
|
require 'mocha/expectation_error'
|
@@ -11,6 +12,7 @@ require 'mocha/change_state_side_effect'
|
|
11
12
|
require 'mocha/cardinality'
|
12
13
|
require 'mocha/configuration'
|
13
14
|
require 'mocha/block_matcher'
|
15
|
+
require 'mocha/backtrace_filter'
|
14
16
|
|
15
17
|
module Mocha
|
16
18
|
# Methods on expectations returned from {Mock#expects}, {Mock#stubs}, {ObjectMethods#expects} and {ObjectMethods#stubs}.
|
@@ -42,7 +44,7 @@ module Mocha
|
|
42
44
|
# object.expected_method
|
43
45
|
# # => verify fails
|
44
46
|
def times(range)
|
45
|
-
@cardinality
|
47
|
+
@cardinality.times(range)
|
46
48
|
self
|
47
49
|
end
|
48
50
|
|
@@ -68,7 +70,7 @@ module Mocha
|
|
68
70
|
# object.expected_method
|
69
71
|
# # => verify fails
|
70
72
|
def twice
|
71
|
-
@cardinality
|
73
|
+
@cardinality.exactly(2)
|
72
74
|
self
|
73
75
|
end
|
74
76
|
|
@@ -93,7 +95,7 @@ module Mocha
|
|
93
95
|
# object.expects(:expected_method).once
|
94
96
|
# # => verify fails
|
95
97
|
def once
|
96
|
-
@cardinality
|
98
|
+
@cardinality.exactly(1)
|
97
99
|
self
|
98
100
|
end
|
99
101
|
|
@@ -110,7 +112,7 @@ module Mocha
|
|
110
112
|
# object.expects(:expected_method).never
|
111
113
|
# # => verify succeeds
|
112
114
|
def never
|
113
|
-
@cardinality
|
115
|
+
@cardinality.exactly(0)
|
114
116
|
self
|
115
117
|
end
|
116
118
|
|
@@ -130,7 +132,7 @@ module Mocha
|
|
130
132
|
# object.expected_method
|
131
133
|
# # => verify fails
|
132
134
|
def at_least(minimum_number_of_times)
|
133
|
-
@cardinality
|
135
|
+
@cardinality.at_least(minimum_number_of_times)
|
134
136
|
self
|
135
137
|
end
|
136
138
|
|
@@ -149,7 +151,6 @@ module Mocha
|
|
149
151
|
# # => verify fails
|
150
152
|
def at_least_once
|
151
153
|
at_least(1)
|
152
|
-
self
|
153
154
|
end
|
154
155
|
|
155
156
|
# Modifies expectation so that the expected method must be called at most a +maximum_number_of_times+.
|
@@ -167,7 +168,7 @@ module Mocha
|
|
167
168
|
# object.expects(:expected_method).at_most(2)
|
168
169
|
# 3.times { object.expected_method } # => unexpected invocation
|
169
170
|
def at_most(maximum_number_of_times)
|
170
|
-
@cardinality
|
171
|
+
@cardinality.at_most(maximum_number_of_times)
|
171
172
|
self
|
172
173
|
end
|
173
174
|
|
@@ -186,20 +187,28 @@ module Mocha
|
|
186
187
|
# 2.times { object.expected_method } # => unexpected invocation
|
187
188
|
def at_most_once
|
188
189
|
at_most(1)
|
189
|
-
self
|
190
190
|
end
|
191
191
|
|
192
|
-
# Modifies expectation so that the expected method must be called with +
|
192
|
+
# Modifies expectation so that the expected method must be called with +expected_parameters_or_matchers+.
|
193
|
+
#
|
194
|
+
# May be used with Ruby literals or variables for exact matching or with parameter matchers for less-specific matching, e.g. {ParameterMatchers#includes}, {ParameterMatchers#has_key}, etc. See {ParameterMatchers} for a list of all available parameter matchers.
|
195
|
+
#
|
196
|
+
# Positional arguments were separated from keyword arguments in Ruby v3 (see {https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0 this article}). In relation to this a new configuration option ({Configuration#strict_keyword_argument_matching=}) is available in Ruby >= 2.7.
|
193
197
|
#
|
194
|
-
#
|
198
|
+
# When {Configuration#strict_keyword_argument_matching=} is set to +false+ (which is currently the default), a positional +Hash+ and a set of keyword arguments passed to {#with} are treated the same for the purposes of parameter matching. However, a deprecation warning will be displayed if a positional +Hash+ matches a set of keyword arguments or vice versa. This is because {Configuration#strict_keyword_argument_matching=} will default to +true+ in the future.
|
195
199
|
#
|
196
|
-
#
|
200
|
+
# When {Configuration#strict_keyword_argument_matching=} is set to +true+, an actual positional +Hash+ will not match an expected set of keyword arguments; and vice versa, an actual set of keyword arguments will not match an expected positional +Hash+, i.e. the parameter matching is stricter.
|
201
|
+
#
|
202
|
+
# @see ParameterMatchers
|
203
|
+
# @see Configuration#strict_keyword_argument_matching=
|
204
|
+
#
|
205
|
+
# @param [*Array<Object,ParameterMatchers::Base>] expected_parameters_or_matchers expected parameter values or parameter matchers.
|
197
206
|
# @yield optional block specifying custom matching.
|
198
|
-
# @yieldparam [*Array] actual_parameters parameters with which expected method was invoked.
|
207
|
+
# @yieldparam [*Array<Object>] actual_parameters parameters with which expected method was invoked.
|
199
208
|
# @yieldreturn [Boolean] +true+ if +actual_parameters+ are acceptable.
|
200
209
|
# @return [Expectation] the same expectation, thereby allowing invocations of other {Expectation} methods to be chained.
|
201
210
|
#
|
202
|
-
# @example Expected method must be called with
|
211
|
+
# @example Expected method must be called with exact parameter values.
|
203
212
|
# object = mock()
|
204
213
|
# object.expects(:expected_method).with(:param1, :param2)
|
205
214
|
# object.expected_method(:param1, :param2)
|
@@ -210,6 +219,43 @@ module Mocha
|
|
210
219
|
# object.expected_method(:param3)
|
211
220
|
# # => verify fails
|
212
221
|
#
|
222
|
+
# @example Expected method must be called with parameters matching parameter matchers.
|
223
|
+
# object = mock()
|
224
|
+
# object.expects(:expected_method).with(includes('string2'), anything)
|
225
|
+
# object.expected_method(['string1', 'string2'], 'any-old-value')
|
226
|
+
# # => verify succeeds
|
227
|
+
#
|
228
|
+
# object = mock()
|
229
|
+
# object.expects(:expected_method).with(includes('string2'), anything)
|
230
|
+
# object.expected_method(['string1'], 'any-old-value')
|
231
|
+
# # => verify fails
|
232
|
+
#
|
233
|
+
# @example Loose keyword argument matching (default)
|
234
|
+
#
|
235
|
+
# class Example
|
236
|
+
# def foo(a, bar:); end
|
237
|
+
# end
|
238
|
+
#
|
239
|
+
# example = Example.new
|
240
|
+
# example.expects(:foo).with('a', bar: 'b')
|
241
|
+
# example.foo('a', { bar: 'b' })
|
242
|
+
# # This passes the test, but would result in an ArgumentError in practice
|
243
|
+
#
|
244
|
+
# @example Strict keyword argument matching
|
245
|
+
#
|
246
|
+
# Mocha.configure do |c|
|
247
|
+
# c.strict_keyword_argument_matching = true
|
248
|
+
# end
|
249
|
+
#
|
250
|
+
# class Example
|
251
|
+
# def foo(a, bar:); end
|
252
|
+
# end
|
253
|
+
#
|
254
|
+
# example = Example.new
|
255
|
+
# example.expects(:foo).with('a', bar: 'b')
|
256
|
+
# example.foo('a', { bar: 'b' })
|
257
|
+
# # This now fails as expected
|
258
|
+
#
|
213
259
|
# @example Expected method must be called with a value divisible by 4.
|
214
260
|
# object = mock()
|
215
261
|
# object.expects(:expected_method).with() { |value| value % 4 == 0 }
|
@@ -220,10 +266,11 @@ module Mocha
|
|
220
266
|
# object.expects(:expected_method).with() { |value| value % 4 == 0 }
|
221
267
|
# object.expected_method(17)
|
222
268
|
# # => verify fails
|
223
|
-
def with(*
|
224
|
-
@parameters_matcher = ParametersMatcher.new(
|
269
|
+
def with(*expected_parameters_or_matchers, &matching_block)
|
270
|
+
@parameters_matcher = ParametersMatcher.new(expected_parameters_or_matchers, self, &matching_block)
|
225
271
|
self
|
226
272
|
end
|
273
|
+
ruby2_keywords(:with)
|
227
274
|
|
228
275
|
# Modifies expectation so that the expected method must be called with a block.
|
229
276
|
#
|
@@ -263,7 +310,11 @@ module Mocha
|
|
263
310
|
self
|
264
311
|
end
|
265
312
|
|
266
|
-
# Modifies expectation so that when the expected method is called, it yields
|
313
|
+
# Modifies expectation so that when the expected method is called, it yields to the block with the specified +parameters+.
|
314
|
+
#
|
315
|
+
# If no +parameters+ are specified, it yields to the block without any parameters.
|
316
|
+
#
|
317
|
+
# If no block is provided, the method will still attempt to yield resulting in a +LocalJumpError+. Note that this is what would happen if a "real" (non-mock) method implementation tried to yield to a non-existent block.
|
267
318
|
#
|
268
319
|
# May be called multiple times on the same expectation for consecutive invocations.
|
269
320
|
#
|
@@ -273,11 +324,10 @@ module Mocha
|
|
273
324
|
#
|
274
325
|
# @example Yield when expected method is invoked.
|
275
326
|
# benchmark = mock()
|
276
|
-
# benchmark.expects(:measure).yields
|
327
|
+
# benchmark.expects(:measure).yields
|
277
328
|
# yielded = false
|
278
|
-
#
|
329
|
+
# benchmark.measure { yielded = true }
|
279
330
|
# yielded # => true
|
280
|
-
# returned_value # => '0.350000 0.400000 0.750000 ( 0.835234)'
|
281
331
|
#
|
282
332
|
# @example Yield parameters when expected method is invoked.
|
283
333
|
# fibonacci = mock()
|
@@ -298,7 +348,9 @@ module Mocha
|
|
298
348
|
multiple_yields(parameters)
|
299
349
|
end
|
300
350
|
|
301
|
-
# Modifies expectation so that when the expected method is called, it yields multiple times per invocation with the specified +parameter_groups
|
351
|
+
# Modifies expectation so that when the expected method is called, it yields multiple times per invocation with the specified +parameter_groups+.
|
352
|
+
#
|
353
|
+
# If no block is provided, the method will still attempt to yield resulting in a +LocalJumpError+. Note that this is what would happen if a "real" (non-mock) method implementation tried to yield to a non-existent block.
|
302
354
|
#
|
303
355
|
# @param [*Array<Array>] parameter_groups each element of +parameter_groups+ should iself be an +Array+ representing the parameters to be passed to the block for a single yield. Any element of +parameter_groups+ that is not an +Array+ is wrapped in an +Array+.
|
304
356
|
# @return [Expectation] the same expectation, thereby allowing invocations of other {Expectation} methods to be chained.
|
@@ -453,9 +505,9 @@ module Mocha
|
|
453
505
|
|
454
506
|
# @overload def then
|
455
507
|
# Used as syntactic sugar to improve readability. It has no effect on state of the expectation.
|
456
|
-
# @overload def then(
|
457
|
-
# Used to change the +state_machine+ to the
|
458
|
-
# @param [StateMachine::State] state_machine.is(state_name) provides a mechanism to change the +state_machine+ into the state specified by +state_name+ when the expected method is invoked.
|
508
|
+
# @overload def then(state)
|
509
|
+
# Used to change the +state_machine+ to the specified state when the expected invocation occurs.
|
510
|
+
# @param [StateMachine::State] state state_machine.is(state_name) provides a mechanism to change the +state_machine+ into the state specified by +state_name+ when the expected method is invoked.
|
459
511
|
#
|
460
512
|
# @see API#states
|
461
513
|
# @see StateMachine
|
@@ -481,17 +533,14 @@ module Mocha
|
|
481
533
|
# radio.expects(:select_channel).with('BBC World Service').when(power.is('on'))
|
482
534
|
# radio.expects(:adjust_volume).with(-5).when(power.is('on'))
|
483
535
|
# radio.expects(:switch_off).then(power.is('off'))
|
484
|
-
def then(
|
485
|
-
|
486
|
-
state = parameters.first
|
487
|
-
add_side_effect(ChangeStateSideEffect.new(state))
|
488
|
-
end
|
536
|
+
def then(state = nil)
|
537
|
+
add_side_effect(ChangeStateSideEffect.new(state)) if state
|
489
538
|
self
|
490
539
|
end
|
491
540
|
|
492
|
-
# Constrains the expectation to occur only when the +state_machine+ is in the state specified by +
|
541
|
+
# Constrains the expectation to occur only when the +state_machine+ is in the state specified by +state_predicate+.
|
493
542
|
#
|
494
|
-
# @param [StateMachine::StatePredicate] state_machine.is(state_name) provides a mechanism to determine whether the +state_machine+ is in the state specified by +
|
543
|
+
# @param [StateMachine::StatePredicate] state_predicate +state_machine.is(state_name)+ provides a mechanism to determine whether the +state_machine+ is in the state specified by +state_predicate+ when the expected method is invoked.
|
495
544
|
# @return [Expectation] the same expectation, thereby allowing invocations of other {Expectation} methods to be chained.
|
496
545
|
#
|
497
546
|
# @see API#states
|
@@ -552,7 +601,7 @@ module Mocha
|
|
552
601
|
@block_matcher = BlockMatchers::OptionalBlock.new
|
553
602
|
@ordering_constraints = []
|
554
603
|
@side_effects = []
|
555
|
-
@cardinality = Cardinality.exactly(1)
|
604
|
+
@cardinality = Cardinality.new.exactly(1)
|
556
605
|
@return_values = ReturnValues.new
|
557
606
|
@yield_parameters = YieldParameters.new
|
558
607
|
@backtrace = backtrace || caller
|
@@ -644,5 +693,11 @@ module Mocha
|
|
644
693
|
signature << " #{@block_matcher.mocha_inspect}" if @block_matcher.mocha_inspect
|
645
694
|
signature
|
646
695
|
end
|
696
|
+
|
697
|
+
# @private
|
698
|
+
def definition_location
|
699
|
+
filter = BacktraceFilter.new
|
700
|
+
filter.filtered(backtrace)[0]
|
701
|
+
end
|
647
702
|
end
|
648
703
|
end
|
data/lib/mocha/inspect.rb
CHANGED
@@ -11,14 +11,16 @@ module Mocha
|
|
11
11
|
end
|
12
12
|
|
13
13
|
module ArrayMethods
|
14
|
-
def mocha_inspect
|
15
|
-
|
14
|
+
def mocha_inspect(wrapped = true)
|
15
|
+
unwrapped = collect(&:mocha_inspect).join(', ')
|
16
|
+
wrapped ? "[#{unwrapped}]" : unwrapped
|
16
17
|
end
|
17
18
|
end
|
18
19
|
|
19
20
|
module HashMethods
|
20
21
|
def mocha_inspect
|
21
|
-
|
22
|
+
unwrapped = collect { |key, value| "#{key.mocha_inspect} => #{value.mocha_inspect}" }.join(', ')
|
23
|
+
Hash.ruby2_keywords_hash?(self) ? unwrapped : "{#{unwrapped}}"
|
22
24
|
end
|
23
25
|
end
|
24
26
|
|
@@ -1,54 +1,26 @@
|
|
1
1
|
require 'mocha/debug'
|
2
|
-
|
3
2
|
require 'mocha/detection/mini_test'
|
4
|
-
|
5
|
-
require 'mocha/integration/mini_test/nothing'
|
6
|
-
require 'mocha/integration/mini_test/version_13'
|
7
|
-
require 'mocha/integration/mini_test/version_140'
|
8
|
-
require 'mocha/integration/mini_test/version_141'
|
9
|
-
require 'mocha/integration/mini_test/version_142_to_172'
|
10
|
-
require 'mocha/integration/mini_test/version_200'
|
11
|
-
require 'mocha/integration/mini_test/version_201_to_222'
|
12
|
-
require 'mocha/integration/mini_test/version_230_to_2101'
|
13
|
-
require 'mocha/integration/mini_test/version_2110_to_2111'
|
14
|
-
require 'mocha/integration/mini_test/version_2112_to_320'
|
15
3
|
require 'mocha/integration/mini_test/adapter'
|
16
4
|
|
17
|
-
require 'mocha/deprecation'
|
18
|
-
|
19
5
|
module Mocha
|
20
6
|
module Integration
|
21
7
|
module MiniTest
|
22
8
|
def self.activate
|
23
|
-
|
24
|
-
|
9
|
+
target = Detection::MiniTest.testcase
|
10
|
+
return false unless target
|
25
11
|
|
12
|
+
mini_test_version = Gem::Version.new(Detection::MiniTest.version)
|
26
13
|
Debug.puts "Detected MiniTest version: #{mini_test_version}"
|
27
14
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
MiniTest::Version2110To2111,
|
32
|
-
MiniTest::Version230To2101,
|
33
|
-
MiniTest::Version201To222,
|
34
|
-
MiniTest::Version200,
|
35
|
-
MiniTest::Version142To172,
|
36
|
-
MiniTest::Version141,
|
37
|
-
MiniTest::Version140,
|
38
|
-
MiniTest::Version13,
|
39
|
-
MiniTest::Nothing
|
40
|
-
].detect { |m| m.applicable_to?(mini_test_version) }
|
15
|
+
unless MiniTest::Adapter.applicable_to?(mini_test_version)
|
16
|
+
raise 'Versions of minitest earlier than v3.3.0 are not supported.'
|
17
|
+
end
|
41
18
|
|
42
|
-
target
|
43
|
-
|
44
|
-
|
45
|
-
Deprecation.warning(
|
46
|
-
'Versions of minitest earlier than v3.3.0 will not be supported in future versions of Mocha.'
|
47
|
-
)
|
48
|
-
end
|
49
|
-
Debug.puts "Applying #{integration_module.description}"
|
50
|
-
target.send(:include, integration_module)
|
19
|
+
unless target < MiniTest::Adapter
|
20
|
+
Debug.puts "Applying #{MiniTest::Adapter.description}"
|
21
|
+
target.send(:include, MiniTest::Adapter)
|
51
22
|
end
|
23
|
+
|
52
24
|
true
|
53
25
|
end
|
54
26
|
end
|