mocha 2.7.1 → 2.8.0
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/RELEASE.md +15 -0
- data/lib/mocha/api.rb +1 -1
- data/lib/mocha/configuration.rb +1 -1
- data/lib/mocha/expectation.rb +2 -2
- data/lib/mocha/parameter_matchers/all_of.rb +30 -21
- data/lib/mocha/parameter_matchers/any_of.rb +36 -27
- data/lib/mocha/parameter_matchers/any_parameters.rb +28 -19
- data/lib/mocha/parameter_matchers/anything.rb +25 -16
- data/lib/mocha/parameter_matchers/base.rb +22 -4
- data/lib/mocha/parameter_matchers/deprecations.rb +46 -0
- data/lib/mocha/parameter_matchers/equals.rb +31 -22
- data/lib/mocha/parameter_matchers/equivalent_uri.rb +30 -21
- data/lib/mocha/parameter_matchers/has_entries.rb +31 -22
- data/lib/mocha/parameter_matchers/has_entry.rb +72 -65
- data/lib/mocha/parameter_matchers/has_key.rb +31 -22
- data/lib/mocha/parameter_matchers/has_keys.rb +31 -22
- data/lib/mocha/parameter_matchers/has_value.rb +31 -22
- data/lib/mocha/parameter_matchers/includes.rb +69 -60
- data/lib/mocha/parameter_matchers/instance_methods.rb +1 -1
- data/lib/mocha/parameter_matchers/instance_of.rb +31 -22
- data/lib/mocha/parameter_matchers/is_a.rb +32 -23
- data/lib/mocha/parameter_matchers/kind_of.rb +31 -22
- data/lib/mocha/parameter_matchers/not.rb +31 -22
- data/lib/mocha/parameter_matchers/optionally.rb +43 -33
- data/lib/mocha/parameter_matchers/positional_or_keyword_hash.rb +6 -1
- data/lib/mocha/parameter_matchers/regexp_matches.rb +31 -22
- data/lib/mocha/parameter_matchers/responds_with.rb +55 -46
- data/lib/mocha/parameter_matchers/yaml_equivalent.rb +30 -21
- data/lib/mocha/parameter_matchers.rb +6 -2
- data/lib/mocha/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f100e1c21f105d22752ae4ffc7740ba8fb351559679d3972ae5eea253725e082
|
|
4
|
+
data.tar.gz: 31729a24bdde2da814bbf7d995fb77fc4c08dd7c98775bdb85d6d36fead87a35
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 57b38d4f7b71f41156ea6dd278416864caed11866f1137a5605491000d3603b8793200d6275962b77ed71aaf09707333b88301451b809e9774e3180d594451cf
|
|
7
|
+
data.tar.gz: 672e486d410a534ecf3eae8613294dfeb894c3fc8d324ae4414328e56ccd31ab9ebb46f13105b95cb3c1b0f35e5cd89eb6eeb5dee7493fbefe200dc03b251f0d
|
data/RELEASE.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# Release Notes
|
|
2
2
|
|
|
3
|
+
## 2.8.0
|
|
4
|
+
|
|
5
|
+
Many thanks to @etiennebarrie for his help in testing v3.0.0 release candidates which led to many of these changes.
|
|
6
|
+
|
|
7
|
+
### External changes
|
|
8
|
+
|
|
9
|
+
* Extract `ParameterMatchers::BaseMethods` module and deprecate inheriting from `ParameterMatchers::Base` class (0ddfbe4b)
|
|
10
|
+
* Move matcher builder methods into `ParameterMatchers::Methods` module and only include that module into `API` (2de41423)
|
|
11
|
+
* Provide deprecated access to matcher builder methods when including `ParameterMatchers` module (299488e1)
|
|
12
|
+
* Provide deprecated access to matcher classes, e.g. `ParameterMatchers::Equals`, from within tests/specs (dcced1b4)
|
|
13
|
+
|
|
14
|
+
### Internal changes
|
|
15
|
+
|
|
16
|
+
* Move `ParameterMatchers#parse_option` -> `HasEntry.parse_option` (9e2a6f66)
|
|
17
|
+
|
|
3
18
|
## 2.7.1
|
|
4
19
|
|
|
5
20
|
### External changes
|
data/lib/mocha/api.rb
CHANGED
data/lib/mocha/configuration.rb
CHANGED
|
@@ -263,7 +263,7 @@ module Mocha
|
|
|
263
263
|
#
|
|
264
264
|
# 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}.
|
|
265
265
|
#
|
|
266
|
-
# 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.
|
|
266
|
+
# Note that +Hash+-related matchers such as {ParameterMatchers::Methods#has_value} or {ParameterMatchers::Methods#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.
|
|
267
267
|
#
|
|
268
268
|
# This configuration option is +false+ by default to enable gradual adoption, but will be +true+ by default in the future.
|
|
269
269
|
#
|
data/lib/mocha/expectation.rb
CHANGED
|
@@ -191,7 +191,7 @@ module Mocha
|
|
|
191
191
|
|
|
192
192
|
# Modifies expectation so that the expected method must be called with +expected_parameters_or_matchers+.
|
|
193
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.
|
|
194
|
+
# May be used with Ruby literals or variables for exact matching or with parameter matchers for less-specific matching, e.g. {ParameterMatchers::Methods#includes}, {ParameterMatchers::Methods#has_key}, etc. See {ParameterMatchers} for a list of all available parameter matchers.
|
|
195
195
|
#
|
|
196
196
|
# Alternatively a block argument can be passed to {#with} to implement custom parameter matching. The block receives the +*actual_parameters+ as its arguments and should return +true+ if they are acceptable or +false+ otherwise. See the example below where a method is expected to be called with a value divisible by 4.
|
|
197
197
|
# The block argument takes precedence over +expected_parameters_or_matchers+. The block may be called multiple times per invocation of the expected method and so it should be idempotent.
|
|
@@ -207,7 +207,7 @@ module Mocha
|
|
|
207
207
|
# @see ParameterMatchers
|
|
208
208
|
# @see Configuration#strict_keyword_argument_matching=
|
|
209
209
|
#
|
|
210
|
-
# @param [Array<Object,ParameterMatchers::
|
|
210
|
+
# @param [Array<Object,ParameterMatchers::BaseMethods>] expected_parameters_or_matchers expected parameter values or parameter matchers.
|
|
211
211
|
# @yield optional block specifying custom matching.
|
|
212
212
|
# @yieldparam [Array<Object>] actual_parameters parameters with which expected method was invoked.
|
|
213
213
|
# @yieldreturn [Boolean] +true+ if +actual_parameters+ are acceptable; +false+ otherwise.
|
|
@@ -1,31 +1,38 @@
|
|
|
1
1
|
require 'mocha/parameter_matchers/base'
|
|
2
|
+
require 'mocha/parameter_matchers/deprecations'
|
|
2
3
|
|
|
3
4
|
module Mocha
|
|
4
5
|
module ParameterMatchers
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
6
|
+
module Methods
|
|
7
|
+
# Matches if all +matchers+ match.
|
|
8
|
+
#
|
|
9
|
+
# @param [*Array<BaseMethods>] matchers parameter matchers.
|
|
10
|
+
# @return [AllOf] parameter matcher.
|
|
11
|
+
#
|
|
12
|
+
# @see Expectation#with
|
|
13
|
+
#
|
|
14
|
+
# @example All parameter matchers match.
|
|
15
|
+
# object = mock()
|
|
16
|
+
# object.expects(:method_1).with(all_of(includes(1), includes(3)))
|
|
17
|
+
# object.method_1([1, 3])
|
|
18
|
+
# # no error raised
|
|
19
|
+
#
|
|
20
|
+
# @example One of the parameter matchers does not match.
|
|
21
|
+
# object = mock()
|
|
22
|
+
# object.expects(:method_1).with(all_of(includes(1), includes(3)))
|
|
23
|
+
# object.method_1([1, 2])
|
|
24
|
+
# # error raised, because method_1 was not called with object including 1 and 3
|
|
25
|
+
def all_of(*matchers)
|
|
26
|
+
AllOf.new(*matchers)
|
|
27
|
+
end
|
|
25
28
|
end
|
|
26
29
|
|
|
30
|
+
define_deprecated_matcher_method(:all_of)
|
|
31
|
+
|
|
27
32
|
# Parameter matcher which combines a number of other matchers using a logical AND.
|
|
28
|
-
class AllOf
|
|
33
|
+
class AllOf
|
|
34
|
+
include BaseMethods
|
|
35
|
+
|
|
29
36
|
# @private
|
|
30
37
|
def initialize(*matchers)
|
|
31
38
|
@matchers = matchers
|
|
@@ -42,5 +49,7 @@ module Mocha
|
|
|
42
49
|
"all_of(#{@matchers.map(&:mocha_inspect).join(', ')})"
|
|
43
50
|
end
|
|
44
51
|
end
|
|
52
|
+
|
|
53
|
+
provide_deprecated_access_to(:AllOf)
|
|
45
54
|
end
|
|
46
55
|
end
|
|
@@ -1,37 +1,44 @@
|
|
|
1
1
|
require 'mocha/parameter_matchers/base'
|
|
2
|
+
require 'mocha/parameter_matchers/deprecations'
|
|
2
3
|
|
|
3
4
|
module Mocha
|
|
4
5
|
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
|
-
|
|
6
|
+
module Methods
|
|
7
|
+
# Matches if any +matchers+ match.
|
|
8
|
+
#
|
|
9
|
+
# @param [*Array<BaseMethods>] matchers parameter matchers.
|
|
10
|
+
# @return [AnyOf] parameter matcher.
|
|
11
|
+
#
|
|
12
|
+
# @see Expectation#with
|
|
13
|
+
#
|
|
14
|
+
# @example One parameter matcher matches.
|
|
15
|
+
# object = mock()
|
|
16
|
+
# object.expects(:method_1).with(any_of(1, 3))
|
|
17
|
+
# object.method_1(1)
|
|
18
|
+
# # no error raised
|
|
19
|
+
#
|
|
20
|
+
# @example The other parameter matcher matches.
|
|
21
|
+
# object = mock()
|
|
22
|
+
# object.expects(:method_1).with(any_of(1, 3))
|
|
23
|
+
# object.method_1(3)
|
|
24
|
+
# # no error raised
|
|
25
|
+
#
|
|
26
|
+
# @example Neither parameter matcher matches.
|
|
27
|
+
# object = mock()
|
|
28
|
+
# object.expects(:method_1).with(any_of(1, 3))
|
|
29
|
+
# object.method_1(2)
|
|
30
|
+
# # error raised, because method_1 was not called with 1 or 3
|
|
31
|
+
def any_of(*matchers)
|
|
32
|
+
AnyOf.new(*matchers)
|
|
33
|
+
end
|
|
31
34
|
end
|
|
32
35
|
|
|
36
|
+
define_deprecated_matcher_method(:any_of)
|
|
37
|
+
|
|
33
38
|
# Parameter matcher which combines a number of other matchers using a logical OR.
|
|
34
|
-
class AnyOf
|
|
39
|
+
class AnyOf
|
|
40
|
+
include BaseMethods
|
|
41
|
+
|
|
35
42
|
# @private
|
|
36
43
|
def initialize(*matchers)
|
|
37
44
|
@matchers = matchers
|
|
@@ -48,5 +55,7 @@ module Mocha
|
|
|
48
55
|
"any_of(#{@matchers.map(&:mocha_inspect).join(', ')})"
|
|
49
56
|
end
|
|
50
57
|
end
|
|
58
|
+
|
|
59
|
+
provide_deprecated_access_to(:AnyOf)
|
|
51
60
|
end
|
|
52
61
|
end
|
|
@@ -1,29 +1,36 @@
|
|
|
1
1
|
require 'mocha/parameter_matchers/base'
|
|
2
|
+
require 'mocha/parameter_matchers/deprecations'
|
|
2
3
|
|
|
3
4
|
module Mocha
|
|
4
5
|
module ParameterMatchers
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
6
|
+
module Methods
|
|
7
|
+
# Matches any parameters. This is used as the default for a newly built expectation.
|
|
8
|
+
#
|
|
9
|
+
# @return [AnyParameters] parameter matcher.
|
|
10
|
+
#
|
|
11
|
+
# @see Expectation#with
|
|
12
|
+
#
|
|
13
|
+
# @example Any parameters will match.
|
|
14
|
+
# object = mock()
|
|
15
|
+
# object.expects(:method_1).with(any_parameters)
|
|
16
|
+
# object.method_1(1, 2, 3, 4)
|
|
17
|
+
# # no error raised
|
|
18
|
+
#
|
|
19
|
+
# object = mock()
|
|
20
|
+
# object.expects(:method_1).with(any_parameters)
|
|
21
|
+
# object.method_1(5, 6, 7, 8, 9, 0)
|
|
22
|
+
# # no error raised
|
|
23
|
+
def any_parameters
|
|
24
|
+
AnyParameters.new
|
|
25
|
+
end
|
|
23
26
|
end
|
|
24
27
|
|
|
28
|
+
define_deprecated_matcher_method(:any_parameters)
|
|
29
|
+
|
|
25
30
|
# Parameter matcher which always matches whatever the parameters.
|
|
26
|
-
class AnyParameters
|
|
31
|
+
class AnyParameters
|
|
32
|
+
include BaseMethods
|
|
33
|
+
|
|
27
34
|
# @private
|
|
28
35
|
def matches?(available_parameters)
|
|
29
36
|
until available_parameters.empty?
|
|
@@ -37,5 +44,7 @@ module Mocha
|
|
|
37
44
|
'any_parameters'
|
|
38
45
|
end
|
|
39
46
|
end
|
|
47
|
+
|
|
48
|
+
provide_deprecated_access_to(:AnyParameters)
|
|
40
49
|
end
|
|
41
50
|
end
|
|
@@ -1,26 +1,33 @@
|
|
|
1
1
|
require 'mocha/parameter_matchers/base'
|
|
2
|
+
require 'mocha/parameter_matchers/deprecations'
|
|
2
3
|
|
|
3
4
|
module Mocha
|
|
4
5
|
module ParameterMatchers
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
6
|
+
module Methods
|
|
7
|
+
# Matches any object.
|
|
8
|
+
#
|
|
9
|
+
# @return [Anything] parameter matcher.
|
|
10
|
+
#
|
|
11
|
+
# @see Expectation#with
|
|
12
|
+
#
|
|
13
|
+
# @example Any object will match.
|
|
14
|
+
# object = mock()
|
|
15
|
+
# object.expects(:method_1).with(anything)
|
|
16
|
+
# object.method_1('foo')
|
|
17
|
+
# object.method_1(789)
|
|
18
|
+
# object.method_1(:bar)
|
|
19
|
+
# # no error raised
|
|
20
|
+
def anything
|
|
21
|
+
Anything.new
|
|
22
|
+
end
|
|
20
23
|
end
|
|
21
24
|
|
|
25
|
+
define_deprecated_matcher_method(:anything)
|
|
26
|
+
|
|
22
27
|
# Parameter matcher which always matches a single parameter.
|
|
23
|
-
class Anything
|
|
28
|
+
class Anything
|
|
29
|
+
include BaseMethods
|
|
30
|
+
|
|
24
31
|
# @private
|
|
25
32
|
def matches?(available_parameters)
|
|
26
33
|
available_parameters.shift
|
|
@@ -32,5 +39,7 @@ module Mocha
|
|
|
32
39
|
'anything'
|
|
33
40
|
end
|
|
34
41
|
end
|
|
42
|
+
|
|
43
|
+
provide_deprecated_access_to(:Anything)
|
|
35
44
|
end
|
|
36
45
|
end
|
|
@@ -1,14 +1,17 @@
|
|
|
1
|
+
require 'mocha/deprecation'
|
|
2
|
+
require 'mocha/parameter_matchers/deprecations'
|
|
3
|
+
|
|
1
4
|
module Mocha
|
|
2
5
|
module ParameterMatchers
|
|
3
|
-
# @abstract
|
|
4
|
-
|
|
6
|
+
# @abstract Include and implement +#matches?+ and +#mocha_inspect+ to define a custom matcher. Also add a suitably named instance method to {Methods} to build an instance of the new matcher c.f. {Methods#equals}.
|
|
7
|
+
module BaseMethods
|
|
5
8
|
# A shorthand way of combining two matchers when both must match.
|
|
6
9
|
#
|
|
7
10
|
# Returns a new {AllOf} parameter matcher combining two matchers using a logical AND.
|
|
8
11
|
#
|
|
9
12
|
# This shorthand will not work with an implicit equals match. Instead, an explicit {Equals} matcher should be used.
|
|
10
13
|
#
|
|
11
|
-
# @param [
|
|
14
|
+
# @param [BaseMethods] other parameter matcher.
|
|
12
15
|
# @return [AllOf] parameter matcher.
|
|
13
16
|
#
|
|
14
17
|
# @see Expectation#with
|
|
@@ -32,7 +35,7 @@ module Mocha
|
|
|
32
35
|
#
|
|
33
36
|
# This shorthand will not work with an implicit equals match. Instead, an explicit {Equals} matcher should be used.
|
|
34
37
|
#
|
|
35
|
-
# @param [
|
|
38
|
+
# @param [BaseMethods] other parameter matcher.
|
|
36
39
|
# @return [AnyOf] parameter matcher.
|
|
37
40
|
#
|
|
38
41
|
# @see Expectation#with
|
|
@@ -56,5 +59,20 @@ module Mocha
|
|
|
56
59
|
AnyOf.new(self, other)
|
|
57
60
|
end
|
|
58
61
|
end
|
|
62
|
+
|
|
63
|
+
# @deprecated Include +BaseMethods+ module instead.
|
|
64
|
+
class Base
|
|
65
|
+
include BaseMethods
|
|
66
|
+
|
|
67
|
+
# @private
|
|
68
|
+
def self.inherited(subclass)
|
|
69
|
+
super
|
|
70
|
+
Deprecation.warning(
|
|
71
|
+
"Include #{BaseMethods} module into #{subclass} instead of inheriting from #{self}."
|
|
72
|
+
)
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
provide_deprecated_access_to(:Base)
|
|
59
77
|
end
|
|
60
78
|
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
require 'mocha/deprecation'
|
|
2
|
+
require 'set'
|
|
3
|
+
|
|
4
|
+
module Mocha
|
|
5
|
+
module ParameterMatchers
|
|
6
|
+
module Methods
|
|
7
|
+
# @private
|
|
8
|
+
def self.included(base)
|
|
9
|
+
base.define_singleton_method(:const_missing) do |name|
|
|
10
|
+
if ParameterMatchers.access_deprecated?(name)
|
|
11
|
+
Mocha::ParameterMatchers.const_get(name).tap do |mod|
|
|
12
|
+
Deprecation.warning(
|
|
13
|
+
"Referencing #{name} outside its namespace is deprecated. Use fully-qualified #{mod} instead."
|
|
14
|
+
)
|
|
15
|
+
end
|
|
16
|
+
else
|
|
17
|
+
super(name)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# @private
|
|
24
|
+
@classes_with_access_deprecated = Set.new
|
|
25
|
+
|
|
26
|
+
# @private
|
|
27
|
+
def self.provide_deprecated_access_to(name)
|
|
28
|
+
@classes_with_access_deprecated.add(name)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# @private
|
|
32
|
+
def self.access_deprecated?(name)
|
|
33
|
+
@classes_with_access_deprecated.include?(name)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# @private
|
|
37
|
+
def self.define_deprecated_matcher_method(name)
|
|
38
|
+
define_method(name) do |*args|
|
|
39
|
+
Deprecation.warning(
|
|
40
|
+
"Calling #{ParameterMatchers}##{name} is deprecated. Use #{Methods}##{name} instead."
|
|
41
|
+
)
|
|
42
|
+
Methods.instance_method(name).bind(self).call(*args)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -1,32 +1,39 @@
|
|
|
1
1
|
require 'mocha/parameter_matchers/base'
|
|
2
|
+
require 'mocha/parameter_matchers/deprecations'
|
|
2
3
|
|
|
3
4
|
module Mocha
|
|
4
5
|
module ParameterMatchers
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
6
|
+
module Methods
|
|
7
|
+
# Matches any +Object+ equalling +value+.
|
|
8
|
+
#
|
|
9
|
+
# @param [Object] value expected value.
|
|
10
|
+
# @return [Equals] parameter matcher.
|
|
11
|
+
#
|
|
12
|
+
# @see Expectation#with
|
|
13
|
+
# @see Object#==
|
|
14
|
+
#
|
|
15
|
+
# @example Actual parameter equals expected parameter.
|
|
16
|
+
# object = mock()
|
|
17
|
+
# object.expects(:method_1).with(equals(2))
|
|
18
|
+
# object.method_1(2)
|
|
19
|
+
# # no error raised
|
|
20
|
+
#
|
|
21
|
+
# @example Actual parameter does not equal expected parameter.
|
|
22
|
+
# object = mock()
|
|
23
|
+
# object.expects(:method_1).with(equals(2))
|
|
24
|
+
# object.method_1(3)
|
|
25
|
+
# # error raised, because method_1 was not called with an +Object+ that equals 2
|
|
26
|
+
def equals(value)
|
|
27
|
+
Equals.new(value)
|
|
28
|
+
end
|
|
26
29
|
end
|
|
27
30
|
|
|
31
|
+
define_deprecated_matcher_method(:equals)
|
|
32
|
+
|
|
28
33
|
# Parameter matcher which matches when actual parameter equals expected value.
|
|
29
|
-
class Equals
|
|
34
|
+
class Equals
|
|
35
|
+
include BaseMethods
|
|
36
|
+
|
|
30
37
|
# @private
|
|
31
38
|
def initialize(value)
|
|
32
39
|
@value = value
|
|
@@ -43,5 +50,7 @@ module Mocha
|
|
|
43
50
|
@value.mocha_inspect
|
|
44
51
|
end
|
|
45
52
|
end
|
|
53
|
+
|
|
54
|
+
provide_deprecated_access_to(:Equals)
|
|
46
55
|
end
|
|
47
56
|
end
|
|
@@ -1,33 +1,40 @@
|
|
|
1
1
|
require 'mocha/parameter_matchers/base'
|
|
2
|
+
require 'mocha/parameter_matchers/deprecations'
|
|
2
3
|
require 'uri'
|
|
3
4
|
require 'cgi'
|
|
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
|
-
|
|
8
|
+
module Methods
|
|
9
|
+
# Matches a URI without regard to the ordering of parameters in the query string.
|
|
10
|
+
#
|
|
11
|
+
# @param [String] uri URI to match.
|
|
12
|
+
# @return [EquivalentUri] parameter matcher.
|
|
13
|
+
#
|
|
14
|
+
# @see Expectation#with
|
|
15
|
+
#
|
|
16
|
+
# @example Actual URI is equivalent.
|
|
17
|
+
# object = mock()
|
|
18
|
+
# object.expects(:method_1).with(equivalent_uri('http://example.com/foo?a=1&b=2))
|
|
19
|
+
# object.method_1('http://example.com/foo?b=2&a=1')
|
|
20
|
+
# # no error raised
|
|
21
|
+
#
|
|
22
|
+
# @example Actual URI is not equivalent.
|
|
23
|
+
# object = mock()
|
|
24
|
+
# object.expects(:method_1).with(equivalent_uri('http://example.com/foo?a=1&b=2))
|
|
25
|
+
# object.method_1('http://example.com/foo?a=1&b=3')
|
|
26
|
+
# # error raised, because the query parameters were different
|
|
27
|
+
def equivalent_uri(uri)
|
|
28
|
+
EquivalentUri.new(uri)
|
|
29
|
+
end
|
|
27
30
|
end
|
|
28
31
|
|
|
32
|
+
define_deprecated_matcher_method(:equivalent_uri)
|
|
33
|
+
|
|
29
34
|
# Parameter matcher which matches URIs with equivalent query strings.
|
|
30
|
-
class EquivalentUri
|
|
35
|
+
class EquivalentUri
|
|
36
|
+
include BaseMethods
|
|
37
|
+
|
|
31
38
|
# @private
|
|
32
39
|
def initialize(uri)
|
|
33
40
|
@uri = URI.parse(uri)
|
|
@@ -53,5 +60,7 @@ module Mocha
|
|
|
53
60
|
URI::Generic::COMPONENT.inject({}) { |h, k| h.merge(k => uri.__send__(k)) }.merge(query: query_hash)
|
|
54
61
|
end
|
|
55
62
|
end
|
|
63
|
+
|
|
64
|
+
provide_deprecated_access_to(:EquivalentUri)
|
|
56
65
|
end
|
|
57
66
|
end
|
|
@@ -1,34 +1,41 @@
|
|
|
1
1
|
require 'mocha/parameter_matchers/base'
|
|
2
2
|
require 'mocha/parameter_matchers/all_of'
|
|
3
3
|
require 'mocha/parameter_matchers/has_entry'
|
|
4
|
+
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
|
-
|
|
8
|
+
module Methods
|
|
9
|
+
# Matches +Hash+ containing all +entries+.
|
|
10
|
+
#
|
|
11
|
+
# @param [Hash] entries expected +Hash+ entries.
|
|
12
|
+
# @return [HasEntries] parameter matcher.
|
|
13
|
+
#
|
|
14
|
+
# @see Expectation#with
|
|
15
|
+
#
|
|
16
|
+
# @example Actual parameter contains all expected entries.
|
|
17
|
+
# object = mock()
|
|
18
|
+
# object.expects(:method_1).with(has_entries('key_1' => 1, 'key_2' => 2))
|
|
19
|
+
# object.method_1('key_1' => 1, 'key_2' => 2, 'key_3' => 3)
|
|
20
|
+
# # no error raised
|
|
21
|
+
#
|
|
22
|
+
# @example Actual parameter does not contain all expected entries.
|
|
23
|
+
# object = mock()
|
|
24
|
+
# object.expects(:method_1).with(has_entries('key_1' => 1, 'key_2' => 2))
|
|
25
|
+
# object.method_1('key_1' => 1, 'key_2' => 99)
|
|
26
|
+
# # error raised, because method_1 was not called with Hash containing entries: 'key_1' => 1, 'key_2' => 2
|
|
27
|
+
#
|
|
28
|
+
def has_entries(entries) # rubocop:disable Naming/PredicateName
|
|
29
|
+
HasEntries.new(entries)
|
|
30
|
+
end
|
|
28
31
|
end
|
|
29
32
|
|
|
33
|
+
define_deprecated_matcher_method(:has_entries)
|
|
34
|
+
|
|
30
35
|
# Parameter matcher which matches when actual parameter contains all expected +Hash+ entries.
|
|
31
|
-
class HasEntries
|
|
36
|
+
class HasEntries
|
|
37
|
+
include BaseMethods
|
|
38
|
+
|
|
32
39
|
# @private
|
|
33
40
|
def initialize(entries, exact: false)
|
|
34
41
|
@entries = entries
|
|
@@ -51,5 +58,7 @@ module Mocha
|
|
|
51
58
|
@exact ? @entries.mocha_inspect : "has_entries(#{@entries.mocha_inspect})"
|
|
52
59
|
end
|
|
53
60
|
end
|
|
61
|
+
|
|
62
|
+
provide_deprecated_access_to(:HasEntries)
|
|
54
63
|
end
|
|
55
64
|
end
|