mocha 2.7.0 → 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/README.md +1 -0
- data/RELEASE.md +23 -0
- data/lib/mocha/api.rb +1 -1
- data/lib/mocha/configuration.rb +8 -1
- data/lib/mocha/expectation.rb +26 -5
- 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/parameters_matcher.rb +7 -3
- data/lib/mocha/version.rb +1 -1
- metadata +4 -3
|
@@ -1,71 +1,78 @@
|
|
|
1
1
|
require 'mocha/parameter_matchers/all_of'
|
|
2
2
|
require 'mocha/parameter_matchers/base'
|
|
3
|
+
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
|
-
|
|
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
|
-
|
|
7
|
+
module Methods
|
|
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)
|
|
67
|
+
end
|
|
65
68
|
end
|
|
66
69
|
|
|
70
|
+
define_deprecated_matcher_method(:includes)
|
|
71
|
+
|
|
67
72
|
# Parameter matcher which matches when actual parameter includes expected values.
|
|
68
|
-
class Includes
|
|
73
|
+
class Includes
|
|
74
|
+
include BaseMethods
|
|
75
|
+
|
|
69
76
|
# @private
|
|
70
77
|
def initialize(*items)
|
|
71
78
|
@items = items
|
|
@@ -98,5 +105,7 @@ module Mocha
|
|
|
98
105
|
"includes(#{item_descriptions.join(', ')})"
|
|
99
106
|
end
|
|
100
107
|
end
|
|
108
|
+
|
|
109
|
+
provide_deprecated_access_to(:Includes)
|
|
101
110
|
end
|
|
102
111
|
end
|
|
@@ -8,7 +8,7 @@ module Mocha
|
|
|
8
8
|
module InstanceMethods
|
|
9
9
|
# @private
|
|
10
10
|
def to_matcher(expectation: nil, top_level: false)
|
|
11
|
-
if
|
|
11
|
+
if is_a?(BaseMethods)
|
|
12
12
|
self
|
|
13
13
|
elsif Hash === self && top_level
|
|
14
14
|
Mocha::ParameterMatchers::PositionalOrKeywordHash.new(self, expectation)
|
|
@@ -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 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)
|
|
28
|
+
end
|
|
26
29
|
end
|
|
27
30
|
|
|
31
|
+
define_deprecated_matcher_method(:instance_of)
|
|
32
|
+
|
|
28
33
|
# Parameter matcher which matches when actual parameter is an instance of the specified class.
|
|
29
|
-
class InstanceOf
|
|
34
|
+
class InstanceOf
|
|
35
|
+
include BaseMethods
|
|
36
|
+
|
|
30
37
|
# @private
|
|
31
38
|
def initialize(klass)
|
|
32
39
|
@klass = klass
|
|
@@ -43,5 +50,7 @@ module Mocha
|
|
|
43
50
|
"instance_of(#{@klass.mocha_inspect})"
|
|
44
51
|
end
|
|
45
52
|
end
|
|
53
|
+
|
|
54
|
+
provide_deprecated_access_to(:InstanceOf)
|
|
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
|
|
|
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
|
-
|
|
6
|
+
module Methods
|
|
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)
|
|
29
|
+
end
|
|
27
30
|
end
|
|
28
31
|
|
|
32
|
+
define_deprecated_matcher_method(:is_a)
|
|
33
|
+
|
|
29
34
|
# Parameter matcher which matches when actual parameter is a specific class.
|
|
30
|
-
class IsA
|
|
35
|
+
class IsA
|
|
36
|
+
include BaseMethods
|
|
37
|
+
|
|
31
38
|
# @private
|
|
32
39
|
def initialize(klass)
|
|
33
40
|
@klass = klass
|
|
@@ -44,5 +51,7 @@ module Mocha
|
|
|
44
51
|
"is_a(#{@klass.mocha_inspect})"
|
|
45
52
|
end
|
|
46
53
|
end
|
|
54
|
+
|
|
55
|
+
provide_deprecated_access_to(:IsA)
|
|
47
56
|
end
|
|
48
57
|
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+ 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)
|
|
28
|
+
end
|
|
26
29
|
end
|
|
27
30
|
|
|
31
|
+
define_deprecated_matcher_method(:kind_of)
|
|
32
|
+
|
|
28
33
|
# Parameter matcher which matches when actual parameter is a kind of specified class.
|
|
29
|
-
class KindOf
|
|
34
|
+
class KindOf
|
|
35
|
+
include BaseMethods
|
|
36
|
+
|
|
30
37
|
# @private
|
|
31
38
|
def initialize(klass)
|
|
32
39
|
@klass = klass
|
|
@@ -45,5 +52,7 @@ module Mocha
|
|
|
45
52
|
"kind_of(#{@klass.mocha_inspect})"
|
|
46
53
|
end
|
|
47
54
|
end
|
|
55
|
+
|
|
56
|
+
provide_deprecated_access_to(:KindOf)
|
|
48
57
|
end
|
|
49
58
|
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
|
-
Not
|
|
6
|
+
module Methods
|
|
7
|
+
# Matches if +matcher+ does *not* match.
|
|
8
|
+
#
|
|
9
|
+
# @param [BaseMethods] 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)
|
|
28
|
+
end
|
|
26
29
|
end
|
|
27
30
|
|
|
31
|
+
define_deprecated_matcher_method(:Not)
|
|
32
|
+
|
|
28
33
|
# Parameter matcher which inverts the logic of the specified matcher using a logical NOT operation.
|
|
29
|
-
class Not
|
|
34
|
+
class Not
|
|
35
|
+
include BaseMethods
|
|
36
|
+
|
|
30
37
|
# @private
|
|
31
38
|
def initialize(matcher)
|
|
32
39
|
@matcher = matcher
|
|
@@ -43,5 +50,7 @@ module Mocha
|
|
|
43
50
|
"Not(#{@matcher.mocha_inspect})"
|
|
44
51
|
end
|
|
45
52
|
end
|
|
53
|
+
|
|
54
|
+
provide_deprecated_access_to(:Not)
|
|
46
55
|
end
|
|
47
56
|
end
|
|
@@ -1,41 +1,49 @@
|
|
|
1
|
+
require 'mocha/parameter_matchers/deprecations'
|
|
2
|
+
|
|
1
3
|
module Mocha
|
|
2
4
|
module ParameterMatchers
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
5
|
+
module Methods
|
|
6
|
+
# Matches optional parameters if available.
|
|
7
|
+
#
|
|
8
|
+
# @param [*Array<BaseMethods>] matchers matchers for optional parameters.
|
|
9
|
+
# @return [Optionally] parameter matcher.
|
|
10
|
+
#
|
|
11
|
+
# @see Expectation#with
|
|
12
|
+
#
|
|
13
|
+
# @example Only the two required parameters are supplied and they both match their expected value.
|
|
14
|
+
# object = mock()
|
|
15
|
+
# object.expects(:method_1).with(1, 2, optionally(3, 4))
|
|
16
|
+
# object.method_1(1, 2)
|
|
17
|
+
# # no error raised
|
|
18
|
+
#
|
|
19
|
+
# @example Both required parameters and one of the optional parameters are supplied and they all match their expected value.
|
|
20
|
+
# object = mock()
|
|
21
|
+
# object.expects(:method_1).with(1, 2, optionally(3, 4))
|
|
22
|
+
# object.method_1(1, 2, 3)
|
|
23
|
+
# # no error raised
|
|
24
|
+
#
|
|
25
|
+
# @example Both required parameters and both of the optional parameters are supplied and they all match their expected value.
|
|
26
|
+
# object = mock()
|
|
27
|
+
# object.expects(:method_1).with(1, 2, optionally(3, 4))
|
|
28
|
+
# object.method_1(1, 2, 3, 4)
|
|
29
|
+
# # no error raised
|
|
30
|
+
#
|
|
31
|
+
# @example One of the actual optional parameters does not match the expected value.
|
|
32
|
+
# object = mock()
|
|
33
|
+
# object.expects(:method_1).with(1, 2, optionally(3, 4))
|
|
34
|
+
# object.method_1(1, 2, 3, 5)
|
|
35
|
+
# # error raised, because optional parameters did not match
|
|
36
|
+
def optionally(*matchers)
|
|
37
|
+
Optionally.new(*matchers)
|
|
38
|
+
end
|
|
35
39
|
end
|
|
36
40
|
|
|
41
|
+
define_deprecated_matcher_method(:optionally)
|
|
42
|
+
|
|
37
43
|
# Parameter matcher which allows optional parameters to be specified.
|
|
38
|
-
class Optionally
|
|
44
|
+
class Optionally
|
|
45
|
+
include BaseMethods
|
|
46
|
+
|
|
39
47
|
# @private
|
|
40
48
|
def initialize(*parameters)
|
|
41
49
|
@matchers = parameters.map(&:to_matcher)
|
|
@@ -57,5 +65,7 @@ module Mocha
|
|
|
57
65
|
"optionally(#{@matchers.map(&:mocha_inspect).join(', ')})"
|
|
58
66
|
end
|
|
59
67
|
end
|
|
68
|
+
|
|
69
|
+
provide_deprecated_access_to(:Optionally)
|
|
60
70
|
end
|
|
61
71
|
end
|
|
@@ -2,11 +2,14 @@ require 'mocha/configuration'
|
|
|
2
2
|
require 'mocha/deprecation'
|
|
3
3
|
require 'mocha/parameter_matchers/base'
|
|
4
4
|
require 'mocha/parameter_matchers/has_entries'
|
|
5
|
+
require 'mocha/parameter_matchers/deprecations'
|
|
5
6
|
|
|
6
7
|
module Mocha
|
|
7
8
|
module ParameterMatchers
|
|
8
9
|
# @private
|
|
9
|
-
class PositionalOrKeywordHash
|
|
10
|
+
class PositionalOrKeywordHash
|
|
11
|
+
include BaseMethods
|
|
12
|
+
|
|
10
13
|
def initialize(value, expectation)
|
|
11
14
|
@value = value
|
|
12
15
|
@expectation = expectation
|
|
@@ -62,5 +65,7 @@ module Mocha
|
|
|
62
65
|
"defined at #{@expectation.definition_location}"
|
|
63
66
|
end
|
|
64
67
|
end
|
|
68
|
+
|
|
69
|
+
provide_deprecated_access_to(:PositionalOrKeywordHash)
|
|
65
70
|
end
|
|
66
71
|
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 that matches +regexp+.
|
|
8
|
+
#
|
|
9
|
+
# @param [Regexp] regexp regular expression to match.
|
|
10
|
+
# @return [RegexpMatches] parameter matcher.
|
|
11
|
+
#
|
|
12
|
+
# @see Expectation#with
|
|
13
|
+
#
|
|
14
|
+
# @example Actual parameter is matched by specified regular expression.
|
|
15
|
+
# object = mock()
|
|
16
|
+
# object.expects(:method_1).with(regexp_matches(/e/))
|
|
17
|
+
# object.method_1('hello')
|
|
18
|
+
# # no error raised
|
|
19
|
+
#
|
|
20
|
+
# @example Actual parameter is not matched by specified regular expression.
|
|
21
|
+
# object = mock()
|
|
22
|
+
# object.expects(:method_1).with(regexp_matches(/a/))
|
|
23
|
+
# object.method_1('hello')
|
|
24
|
+
# # error raised, because method_1 was not called with a parameter that matched the
|
|
25
|
+
# # regular expression
|
|
26
|
+
def regexp_matches(regexp)
|
|
27
|
+
RegexpMatches.new(regexp)
|
|
28
|
+
end
|
|
26
29
|
end
|
|
27
30
|
|
|
31
|
+
define_deprecated_matcher_method(:regexp_matches)
|
|
32
|
+
|
|
28
33
|
# Parameter matcher which matches if specified regular expression matches actual paramter.
|
|
29
|
-
class RegexpMatches
|
|
34
|
+
class RegexpMatches
|
|
35
|
+
include BaseMethods
|
|
36
|
+
|
|
30
37
|
# @private
|
|
31
38
|
def initialize(regexp)
|
|
32
39
|
@regexp = regexp
|
|
@@ -44,5 +51,7 @@ module Mocha
|
|
|
44
51
|
"regexp_matches(#{@regexp.mocha_inspect})"
|
|
45
52
|
end
|
|
46
53
|
end
|
|
54
|
+
|
|
55
|
+
provide_deprecated_access_to(:RegexpMatches)
|
|
47
56
|
end
|
|
48
57
|
end
|