mocha 2.8.0 → 3.0.0.pre.rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +67 -3
- data/.rubocop_todo.yml +25 -13
- data/Gemfile +11 -27
- data/README.md +3 -4
- data/RELEASE.md +30 -8
- data/Rakefile +6 -5
- data/gemfiles/Gemfile.minitest.latest +3 -3
- data/gemfiles/Gemfile.rubocop +9 -0
- data/gemfiles/Gemfile.test-unit.latest +3 -3
- data/lib/mocha/any_instance_method.rb +2 -0
- data/lib/mocha/any_instance_receiver.rb +20 -0
- data/lib/mocha/api.rb +5 -3
- data/lib/mocha/argument_iterator.rb +5 -5
- data/lib/mocha/backtrace_filter.rb +2 -0
- data/lib/mocha/{block_matcher.rb → block_matchers.rb} +2 -0
- data/lib/mocha/cardinality.rb +2 -2
- data/lib/mocha/central.rb +4 -0
- data/lib/mocha/change_state_side_effect.rb +2 -0
- data/lib/mocha/class_methods.rb +5 -4
- data/lib/mocha/configuration.rb +19 -42
- data/lib/mocha/default_name.rb +15 -0
- data/lib/mocha/default_receiver.rb +13 -0
- data/lib/mocha/deprecation.rb +15 -9
- data/lib/mocha/detection/minitest.rb +2 -0
- data/lib/mocha/detection/test_unit.rb +4 -1
- data/lib/mocha/error_with_filtered_backtrace.rb +2 -0
- data/lib/mocha/exception_raiser.rb +3 -0
- data/lib/mocha/expectation.rb +59 -25
- data/lib/mocha/expectation_error.rb +2 -0
- data/lib/mocha/expectation_error_factory.rb +2 -0
- data/lib/mocha/expectation_list.rb +2 -0
- data/lib/mocha/hooks.rb +2 -0
- data/lib/mocha/impersonating_any_instance_name.rb +13 -0
- data/lib/mocha/impersonating_name.rb +13 -0
- data/lib/mocha/in_state_ordering_constraint.rb +2 -0
- data/lib/mocha/inspect.rb +13 -10
- data/lib/mocha/instance_method.rb +2 -0
- data/lib/mocha/integration/assertion_counter.rb +2 -0
- data/lib/mocha/integration/minitest/adapter.rb +3 -0
- data/lib/mocha/integration/minitest.rb +4 -3
- data/lib/mocha/integration/monkey_patcher.rb +4 -2
- data/lib/mocha/integration/test_unit/adapter.rb +3 -0
- data/lib/mocha/integration/test_unit.rb +4 -3
- data/lib/mocha/invocation.rb +9 -6
- data/lib/mocha/logger.rb +2 -0
- data/lib/mocha/macos_version.rb +2 -0
- data/lib/mocha/method_matcher.rb +2 -0
- data/lib/mocha/minitest.rb +2 -1
- data/lib/mocha/mock.rb +8 -8
- data/lib/mocha/mockery.rb +16 -6
- data/lib/mocha/name.rb +13 -0
- data/lib/mocha/not_initialized_error.rb +2 -0
- data/lib/mocha/object_methods.rb +7 -5
- data/lib/mocha/object_receiver.rb +20 -0
- data/lib/mocha/parameter_matchers/all_of.rb +23 -28
- data/lib/mocha/parameter_matchers/any_of.rb +29 -34
- data/lib/mocha/parameter_matchers/any_parameters.rb +21 -26
- data/lib/mocha/parameter_matchers/anything.rb +18 -23
- data/lib/mocha/parameter_matchers/base.rb +5 -21
- data/lib/mocha/parameter_matchers/equals.rb +24 -29
- data/lib/mocha/parameter_matchers/equivalent_uri.rb +23 -28
- data/lib/mocha/parameter_matchers/has_entries.rb +24 -29
- data/lib/mocha/parameter_matchers/has_entry.rb +68 -70
- data/lib/mocha/parameter_matchers/has_key.rb +25 -29
- data/lib/mocha/parameter_matchers/has_keys.rb +25 -30
- data/lib/mocha/parameter_matchers/has_value.rb +25 -29
- data/lib/mocha/parameter_matchers/includes.rb +65 -73
- data/lib/mocha/parameter_matchers/instance_methods.rb +5 -3
- data/lib/mocha/parameter_matchers/instance_of.rb +24 -29
- data/lib/mocha/parameter_matchers/is_a.rb +25 -30
- data/lib/mocha/parameter_matchers/kind_of.rb +24 -29
- data/lib/mocha/parameter_matchers/not.rb +24 -29
- data/lib/mocha/parameter_matchers/optionally.rb +35 -40
- data/lib/mocha/parameter_matchers/positional_or_keyword_hash.rb +39 -19
- data/lib/mocha/parameter_matchers/regexp_matches.rb +25 -29
- data/lib/mocha/parameter_matchers/responds_with.rb +48 -53
- data/lib/mocha/parameter_matchers/yaml_equivalent.rb +23 -28
- data/lib/mocha/parameter_matchers.rb +4 -6
- data/lib/mocha/parameters_matcher.rb +9 -1
- data/lib/mocha/raised_exception.rb +2 -0
- data/lib/mocha/return_values.rb +2 -0
- data/lib/mocha/ruby_version.rb +3 -0
- data/lib/mocha/sequence.rb +2 -0
- data/lib/mocha/single_return_value.rb +1 -1
- data/lib/mocha/state_machine.rb +2 -0
- data/lib/mocha/stubbed_method.rb +9 -2
- data/lib/mocha/stubbing_error.rb +2 -0
- data/lib/mocha/test_unit.rb +2 -1
- data/lib/mocha/thrower.rb +2 -0
- data/lib/mocha/thrown_object.rb +2 -0
- data/lib/mocha/version.rb +3 -1
- data/lib/mocha/yield_parameters.rb +2 -0
- data/lib/mocha.rb +5 -0
- data/mocha.gemspec +10 -4
- metadata +17 -16
- data/lib/mocha/debug.rb +0 -9
- data/lib/mocha/integration/minitest/exception_translation.rb +0 -14
- data/lib/mocha/is_a.rb +0 -7
- data/lib/mocha/names.rb +0 -43
- data/lib/mocha/parameter_matchers/deprecations.rb +0 -46
- data/lib/mocha/receivers.rb +0 -45
|
@@ -1,77 +1,74 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'mocha/parameter_matchers/all_of'
|
|
2
4
|
require 'mocha/parameter_matchers/base'
|
|
3
|
-
require 'mocha/parameter_matchers/deprecations'
|
|
4
5
|
|
|
5
6
|
module Mocha
|
|
6
7
|
module ParameterMatchers
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
Includes.new(*items)
|
|
67
|
-
end
|
|
8
|
+
# Matches any object that responds with +true+ to +include?(item)+
|
|
9
|
+
# for all items.
|
|
10
|
+
#
|
|
11
|
+
# @param [*Array] items expected items.
|
|
12
|
+
# @return [Includes] parameter matcher.
|
|
13
|
+
#
|
|
14
|
+
# @see Expectation#with
|
|
15
|
+
#
|
|
16
|
+
# @example Actual parameter includes all items.
|
|
17
|
+
# object = mock()
|
|
18
|
+
# object.expects(:method_1).with(includes('foo', 'bar'))
|
|
19
|
+
# object.method_1(['foo', 'bar', 'baz'])
|
|
20
|
+
# # no error raised
|
|
21
|
+
#
|
|
22
|
+
# @example Actual parameter does not include all items.
|
|
23
|
+
# object.method_1(['foo', 'baz'])
|
|
24
|
+
# # error raised, because ['foo', 'baz'] does not include 'bar'.
|
|
25
|
+
#
|
|
26
|
+
# @example Actual parameter includes item which matches nested matcher.
|
|
27
|
+
# object = mock()
|
|
28
|
+
# object.expects(:method_1).with(includes(has_key(:key)))
|
|
29
|
+
# object.method_1(['foo', 'bar', {key: 'baz'}])
|
|
30
|
+
# # no error raised
|
|
31
|
+
#
|
|
32
|
+
# @example Actual parameter does not include item matching nested matcher.
|
|
33
|
+
# object.method_1(['foo', 'bar', {:other_key => 'baz'}])
|
|
34
|
+
# # error raised, because no element matches `has_key(:key)` matcher
|
|
35
|
+
#
|
|
36
|
+
# @example Actual parameter is a String including substring.
|
|
37
|
+
# object = mock()
|
|
38
|
+
# object.expects(:method_1).with(includes('bar'))
|
|
39
|
+
# object.method_1('foobarbaz')
|
|
40
|
+
# # no error raised
|
|
41
|
+
#
|
|
42
|
+
# @example Actual parameter is a String not including substring.
|
|
43
|
+
# object.method_1('foobaz')
|
|
44
|
+
# # error raised, because 'foobaz' does not include 'bar'
|
|
45
|
+
#
|
|
46
|
+
# @example Actual parameter is a Hash including the given key.
|
|
47
|
+
# object = mock()
|
|
48
|
+
# object.expects(:method_1).with(includes(:bar))
|
|
49
|
+
# object.method_1({foo: 1, bar: 2})
|
|
50
|
+
# # no error raised
|
|
51
|
+
#
|
|
52
|
+
# @example Actual parameter is a Hash without the given key.
|
|
53
|
+
# object.method_1({foo: 1, baz: 2})
|
|
54
|
+
# # error raised, because hash does not include key 'bar'
|
|
55
|
+
#
|
|
56
|
+
# @example Actual parameter is a Hash with a key matching the given matcher.
|
|
57
|
+
# object = mock()
|
|
58
|
+
# object.expects(:method_1).with(includes(regexp_matches(/ar/)))
|
|
59
|
+
# object.method_1({'foo' => 1, 'bar' => 2})
|
|
60
|
+
# # no error raised
|
|
61
|
+
#
|
|
62
|
+
# @example Actual parameter is a Hash no key matching the given matcher.
|
|
63
|
+
# object.method_1({'foo' => 1, 'baz' => 3})
|
|
64
|
+
# # error raised, because hash does not include a key matching /ar/
|
|
65
|
+
def includes(*items)
|
|
66
|
+
Includes.new(*items)
|
|
68
67
|
end
|
|
69
68
|
|
|
70
|
-
define_deprecated_matcher_method(:includes)
|
|
71
|
-
|
|
72
69
|
# Parameter matcher which matches when actual parameter includes expected values.
|
|
73
70
|
class Includes
|
|
74
|
-
include
|
|
71
|
+
include Base
|
|
75
72
|
|
|
76
73
|
# @private
|
|
77
74
|
def initialize(*items)
|
|
@@ -79,25 +76,22 @@ module Mocha
|
|
|
79
76
|
end
|
|
80
77
|
|
|
81
78
|
# @private
|
|
82
|
-
# rubocop:disable Metrics/PerceivedComplexity
|
|
83
79
|
def matches?(available_parameters)
|
|
84
80
|
parameter = available_parameters.shift
|
|
85
81
|
return false unless parameter.respond_to?(:include?)
|
|
82
|
+
|
|
86
83
|
if @items.size == 1
|
|
87
|
-
# rubocop:disable Style/GuardClause
|
|
88
84
|
if parameter.respond_to?(:any?) && !parameter.is_a?(String)
|
|
89
85
|
parameter = parameter.keys if parameter.is_a?(Hash)
|
|
90
|
-
|
|
86
|
+
parameter.any? { |p| @items.first.to_matcher.matches?([p]) }
|
|
91
87
|
else
|
|
92
|
-
|
|
88
|
+
parameter.include?(@items.first)
|
|
93
89
|
end
|
|
94
|
-
# rubocop:enable Style/GuardClause
|
|
95
90
|
else
|
|
96
91
|
includes_matchers = @items.map { |item| Includes.new(item) }
|
|
97
92
|
AllOf.new(*includes_matchers).matches?([parameter])
|
|
98
93
|
end
|
|
99
94
|
end
|
|
100
|
-
# rubocop:enable Metrics/PerceivedComplexity
|
|
101
95
|
|
|
102
96
|
# @private
|
|
103
97
|
def mocha_inspect
|
|
@@ -105,7 +99,5 @@ module Mocha
|
|
|
105
99
|
"includes(#{item_descriptions.join(', ')})"
|
|
106
100
|
end
|
|
107
101
|
end
|
|
108
|
-
|
|
109
|
-
provide_deprecated_access_to(:Includes)
|
|
110
102
|
end
|
|
111
103
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'mocha/parameter_matchers/base'
|
|
2
4
|
require 'mocha/parameter_matchers/equals'
|
|
3
5
|
require 'mocha/parameter_matchers/positional_or_keyword_hash'
|
|
@@ -7,11 +9,11 @@ module Mocha
|
|
|
7
9
|
# @private
|
|
8
10
|
module InstanceMethods
|
|
9
11
|
# @private
|
|
10
|
-
def to_matcher(expectation: nil, top_level: false)
|
|
11
|
-
if
|
|
12
|
+
def to_matcher(expectation: nil, top_level: false, last: false)
|
|
13
|
+
if Base === self
|
|
12
14
|
self
|
|
13
15
|
elsif Hash === self && top_level
|
|
14
|
-
Mocha::ParameterMatchers::PositionalOrKeywordHash.new(self, expectation)
|
|
16
|
+
Mocha::ParameterMatchers::PositionalOrKeywordHash.new(self, expectation, last)
|
|
15
17
|
else
|
|
16
18
|
Mocha::ParameterMatchers::Equals.new(self)
|
|
17
19
|
end
|
|
@@ -1,38 +1,35 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'mocha/parameter_matchers/base'
|
|
2
|
-
require 'mocha/parameter_matchers/deprecations'
|
|
3
4
|
|
|
4
5
|
module Mocha
|
|
5
6
|
module ParameterMatchers
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
InstanceOf.new(klass)
|
|
28
|
-
end
|
|
7
|
+
# Matches any object that is an instance of +klass+
|
|
8
|
+
#
|
|
9
|
+
# @param [Class] klass expected class.
|
|
10
|
+
# @return [InstanceOf] parameter matcher.
|
|
11
|
+
#
|
|
12
|
+
# @see Expectation#with
|
|
13
|
+
# @see Kernel#instance_of?
|
|
14
|
+
#
|
|
15
|
+
# @example Actual parameter is an instance of +String+.
|
|
16
|
+
# object = mock()
|
|
17
|
+
# object.expects(:method_1).with(instance_of(String))
|
|
18
|
+
# object.method_1('string')
|
|
19
|
+
# # no error raised
|
|
20
|
+
#
|
|
21
|
+
# @example Actual parameter is not an instance of +String+.
|
|
22
|
+
# object = mock()
|
|
23
|
+
# object.expects(:method_1).with(instance_of(String))
|
|
24
|
+
# object.method_1(99)
|
|
25
|
+
# # error raised, because method_1 was not called with an instance of String
|
|
26
|
+
def instance_of(klass)
|
|
27
|
+
InstanceOf.new(klass)
|
|
29
28
|
end
|
|
30
29
|
|
|
31
|
-
define_deprecated_matcher_method(:instance_of)
|
|
32
|
-
|
|
33
30
|
# Parameter matcher which matches when actual parameter is an instance of the specified class.
|
|
34
31
|
class InstanceOf
|
|
35
|
-
include
|
|
32
|
+
include Base
|
|
36
33
|
|
|
37
34
|
# @private
|
|
38
35
|
def initialize(klass)
|
|
@@ -50,7 +47,5 @@ module Mocha
|
|
|
50
47
|
"instance_of(#{@klass.mocha_inspect})"
|
|
51
48
|
end
|
|
52
49
|
end
|
|
53
|
-
|
|
54
|
-
provide_deprecated_access_to(:InstanceOf)
|
|
55
50
|
end
|
|
56
51
|
end
|
|
@@ -1,39 +1,36 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'mocha/parameter_matchers/base'
|
|
2
|
-
require 'mocha/parameter_matchers/deprecations'
|
|
3
4
|
|
|
4
5
|
module Mocha
|
|
5
6
|
module ParameterMatchers
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
IsA.new(klass)
|
|
29
|
-
end
|
|
7
|
+
# Matches any object that is a +klass+.
|
|
8
|
+
#
|
|
9
|
+
# @param [Class] klass expected class.
|
|
10
|
+
# @return [IsA] parameter matcher.
|
|
11
|
+
#
|
|
12
|
+
# @see Expectation#with
|
|
13
|
+
# @see Kernel#is_a?
|
|
14
|
+
#
|
|
15
|
+
# @example Actual parameter is a +Integer+.
|
|
16
|
+
# object = mock()
|
|
17
|
+
# object.expects(:method_1).with(is_a(Integer))
|
|
18
|
+
# object.method_1(99)
|
|
19
|
+
# # no error raised
|
|
20
|
+
#
|
|
21
|
+
# @example Actual parameter is not a +Integer+.
|
|
22
|
+
# object = mock()
|
|
23
|
+
# object.expects(:method_1).with(is_a(Integer))
|
|
24
|
+
# object.method_1('string')
|
|
25
|
+
# # error raised, because method_1 was not called with an Integer
|
|
26
|
+
#
|
|
27
|
+
def is_a(klass) # rubocop:disable Naming/PredicateName
|
|
28
|
+
IsA.new(klass)
|
|
30
29
|
end
|
|
31
30
|
|
|
32
|
-
define_deprecated_matcher_method(:is_a)
|
|
33
|
-
|
|
34
31
|
# Parameter matcher which matches when actual parameter is a specific class.
|
|
35
32
|
class IsA
|
|
36
|
-
include
|
|
33
|
+
include Base
|
|
37
34
|
|
|
38
35
|
# @private
|
|
39
36
|
def initialize(klass)
|
|
@@ -51,7 +48,5 @@ module Mocha
|
|
|
51
48
|
"is_a(#{@klass.mocha_inspect})"
|
|
52
49
|
end
|
|
53
50
|
end
|
|
54
|
-
|
|
55
|
-
provide_deprecated_access_to(:IsA)
|
|
56
51
|
end
|
|
57
52
|
end
|
|
@@ -1,38 +1,35 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'mocha/parameter_matchers/base'
|
|
2
|
-
require 'mocha/parameter_matchers/deprecations'
|
|
3
4
|
|
|
4
5
|
module Mocha
|
|
5
6
|
module ParameterMatchers
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
KindOf.new(klass)
|
|
28
|
-
end
|
|
7
|
+
# Matches any +Object+ that is a kind of +klass+.
|
|
8
|
+
#
|
|
9
|
+
# @param [Class] klass expected class.
|
|
10
|
+
# @return [KindOf] parameter matcher.
|
|
11
|
+
#
|
|
12
|
+
# @see Expectation#with
|
|
13
|
+
# @see Kernel#kind_of?
|
|
14
|
+
#
|
|
15
|
+
# @example Actual parameter is a kind of +Integer+.
|
|
16
|
+
# object = mock()
|
|
17
|
+
# object.expects(:method_1).with(kind_of(Integer))
|
|
18
|
+
# object.method_1(99)
|
|
19
|
+
# # no error raised
|
|
20
|
+
#
|
|
21
|
+
# @example Actual parameter is not a kind of +Integer+.
|
|
22
|
+
# object = mock()
|
|
23
|
+
# object.expects(:method_1).with(kind_of(Integer))
|
|
24
|
+
# object.method_1('string')
|
|
25
|
+
# # error raised, because method_1 was not called with a kind of Integer
|
|
26
|
+
def kind_of(klass)
|
|
27
|
+
KindOf.new(klass)
|
|
29
28
|
end
|
|
30
29
|
|
|
31
|
-
define_deprecated_matcher_method(:kind_of)
|
|
32
|
-
|
|
33
30
|
# Parameter matcher which matches when actual parameter is a kind of specified class.
|
|
34
31
|
class KindOf
|
|
35
|
-
include
|
|
32
|
+
include Base
|
|
36
33
|
|
|
37
34
|
# @private
|
|
38
35
|
def initialize(klass)
|
|
@@ -52,7 +49,5 @@ module Mocha
|
|
|
52
49
|
"kind_of(#{@klass.mocha_inspect})"
|
|
53
50
|
end
|
|
54
51
|
end
|
|
55
|
-
|
|
56
|
-
provide_deprecated_access_to(:KindOf)
|
|
57
52
|
end
|
|
58
53
|
end
|
|
@@ -1,38 +1,35 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'mocha/parameter_matchers/base'
|
|
2
|
-
require 'mocha/parameter_matchers/deprecations'
|
|
3
4
|
|
|
4
5
|
module Mocha
|
|
5
6
|
module ParameterMatchers
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
Not.new(matcher)
|
|
28
|
-
end
|
|
7
|
+
# Matches if +matcher+ does *not* match.
|
|
8
|
+
#
|
|
9
|
+
# @param [Base] matcher matcher whose logic to invert.
|
|
10
|
+
# @return [Not] parameter matcher.
|
|
11
|
+
#
|
|
12
|
+
# @see Expectation#with
|
|
13
|
+
#
|
|
14
|
+
# @example Actual parameter does not include the value +1+.
|
|
15
|
+
# object = mock()
|
|
16
|
+
# object.expects(:method_1).with(Not(includes(1)))
|
|
17
|
+
# object.method_1([0, 2, 3])
|
|
18
|
+
# # no error raised
|
|
19
|
+
#
|
|
20
|
+
# @example Actual parameter does include the value +1+.
|
|
21
|
+
# object = mock()
|
|
22
|
+
# object.expects(:method_1).with(Not(includes(1)))
|
|
23
|
+
# object.method_1([0, 1, 2, 3])
|
|
24
|
+
# # error raised, because method_1 was not called with object not including 1
|
|
25
|
+
#
|
|
26
|
+
def Not(matcher) # rubocop:disable Naming/MethodName
|
|
27
|
+
Not.new(matcher)
|
|
29
28
|
end
|
|
30
29
|
|
|
31
|
-
define_deprecated_matcher_method(:Not)
|
|
32
|
-
|
|
33
30
|
# Parameter matcher which inverts the logic of the specified matcher using a logical NOT operation.
|
|
34
31
|
class Not
|
|
35
|
-
include
|
|
32
|
+
include Base
|
|
36
33
|
|
|
37
34
|
# @private
|
|
38
35
|
def initialize(matcher)
|
|
@@ -50,7 +47,5 @@ module Mocha
|
|
|
50
47
|
"Not(#{@matcher.mocha_inspect})"
|
|
51
48
|
end
|
|
52
49
|
end
|
|
53
|
-
|
|
54
|
-
provide_deprecated_access_to(:Not)
|
|
55
50
|
end
|
|
56
51
|
end
|
|
@@ -1,48 +1,44 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Mocha
|
|
4
4
|
module ParameterMatchers
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
Optionally.new(*matchers)
|
|
38
|
-
end
|
|
5
|
+
# Matches optional parameters if available.
|
|
6
|
+
#
|
|
7
|
+
# @param [*Array<Base>] matchers matchers for optional parameters.
|
|
8
|
+
# @return [Optionally] parameter matcher.
|
|
9
|
+
#
|
|
10
|
+
# @see Expectation#with
|
|
11
|
+
#
|
|
12
|
+
# @example Only the two required parameters are supplied and they both match their expected value.
|
|
13
|
+
# object = mock()
|
|
14
|
+
# object.expects(:method_1).with(1, 2, optionally(3, 4))
|
|
15
|
+
# object.method_1(1, 2)
|
|
16
|
+
# # no error raised
|
|
17
|
+
#
|
|
18
|
+
# @example Both required parameters and one of the optional parameters are supplied and they all match their expected value.
|
|
19
|
+
# object = mock()
|
|
20
|
+
# object.expects(:method_1).with(1, 2, optionally(3, 4))
|
|
21
|
+
# object.method_1(1, 2, 3)
|
|
22
|
+
# # no error raised
|
|
23
|
+
#
|
|
24
|
+
# @example Both required parameters and both of the optional parameters are supplied and they all match their expected value.
|
|
25
|
+
# object = mock()
|
|
26
|
+
# object.expects(:method_1).with(1, 2, optionally(3, 4))
|
|
27
|
+
# object.method_1(1, 2, 3, 4)
|
|
28
|
+
# # no error raised
|
|
29
|
+
#
|
|
30
|
+
# @example One of the actual optional parameters does not match the expected value.
|
|
31
|
+
# object = mock()
|
|
32
|
+
# object.expects(:method_1).with(1, 2, optionally(3, 4))
|
|
33
|
+
# object.method_1(1, 2, 3, 5)
|
|
34
|
+
# # error raised, because optional parameters did not match
|
|
35
|
+
def optionally(*matchers)
|
|
36
|
+
Optionally.new(*matchers)
|
|
39
37
|
end
|
|
40
38
|
|
|
41
|
-
define_deprecated_matcher_method(:optionally)
|
|
42
|
-
|
|
43
39
|
# Parameter matcher which allows optional parameters to be specified.
|
|
44
40
|
class Optionally
|
|
45
|
-
include
|
|
41
|
+
include Base
|
|
46
42
|
|
|
47
43
|
# @private
|
|
48
44
|
def initialize(*parameters)
|
|
@@ -55,6 +51,7 @@ module Mocha
|
|
|
55
51
|
while !available_parameters.empty? && (index < @matchers.length)
|
|
56
52
|
matcher = @matchers[index]
|
|
57
53
|
return false unless matcher.matches?(available_parameters)
|
|
54
|
+
|
|
58
55
|
index += 1
|
|
59
56
|
end
|
|
60
57
|
true
|
|
@@ -65,7 +62,5 @@ module Mocha
|
|
|
65
62
|
"optionally(#{@matchers.map(&:mocha_inspect).join(', ')})"
|
|
66
63
|
end
|
|
67
64
|
end
|
|
68
|
-
|
|
69
|
-
provide_deprecated_access_to(:Optionally)
|
|
70
65
|
end
|
|
71
66
|
end
|