flexmock 2.4.2 → 2.4.5
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 +10 -0
- data/lib/flexmock/argument_matchers.rb +33 -0
- data/lib/flexmock/composite_expectation.rb +2 -1
- data/lib/flexmock/core_class_methods.rb +12 -0
- data/lib/flexmock/expectation.rb +7 -1
- data/lib/flexmock/expectation_recorder.rb +1 -1
- data/lib/flexmock/partial_mock.rb +1 -0
- data/lib/flexmock/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 95477346c9b4f5310e7aab502150273b0473194442fdee505ab366efbbba77bf
|
4
|
+
data.tar.gz: cf44602d7ddfa3197ff847e476da46adc9b82a07382c100e2eb149abc56ae285
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc7337acd6e30ede212fbe23f44149c9b76693dacec228e06fac7b4f60bb684d9a641b2fd3b5be3b7fe401cc22bc8eeaff01883808fd594c6d7e6209f9128db5
|
7
|
+
data.tar.gz: cc11b26a6a3508adae240889c9c1e1c2484876b965f6dc82f54282061c8405bcf52d8e5b6f15a963239c9cf939cd50f9c2c74ad82bf9d469bec1a25d021c1ae8
|
data/README.md
CHANGED
@@ -22,6 +22,16 @@ Only significant changes (new APIs, deprecated APIs or backward-compatible
|
|
22
22
|
changes) are documented here, a.k.a. minor or major version bumps. If you want a
|
23
23
|
detailed changelog, go over the commit log in github (it's pretty low-traffic)
|
24
24
|
|
25
|
+
2.4.0:
|
26
|
+
- forward-compatible implementation of `with_kw_args`, `with_any_kw_args`,
|
27
|
+
`with_block` and `with_no_block`. The objective of this release is to ensure
|
28
|
+
that any test changes needed to handle Ruby 3 (along with flexmock 3) can run
|
29
|
+
on ruby 2.7 and flexmock 2.4
|
30
|
+
- the default behavior of flexmock 2 regarding proc matching, that is that one
|
31
|
+
needs to match them explicitly, is unchanged. Use `with_optional_block` instead
|
32
|
+
of passing `optional_proc` to `with`, to match optionally (IMPORTANT
|
33
|
+
the explicit `with` methods that match blocks are called `block`, not `proc`)
|
34
|
+
|
25
35
|
2.3.0:
|
26
36
|
- implemented validation of call arity for partial mocks. By setting
|
27
37
|
FlexMock.partials_verify_signatures = true
|
@@ -67,6 +67,39 @@ class FlexMock
|
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
|
+
####################################################################
|
71
|
+
# Match hashes that match all the fields of +hash+.
|
72
|
+
class KwArgsMatcher
|
73
|
+
def initialize(expected)
|
74
|
+
@expected = expected
|
75
|
+
end
|
76
|
+
def ===(target)
|
77
|
+
return false unless target.kind_of?(Hash)
|
78
|
+
matching = @expected.all? do |k, v|
|
79
|
+
v === target[k] || v == target[k]
|
80
|
+
end
|
81
|
+
return false unless matching
|
82
|
+
|
83
|
+
@expected.size == target.size
|
84
|
+
end
|
85
|
+
def inspect
|
86
|
+
args = @expected.map do |k, v|
|
87
|
+
k_s = case k
|
88
|
+
when Symbol
|
89
|
+
"#{k}: "
|
90
|
+
else
|
91
|
+
"#{k.inspect} => "
|
92
|
+
end
|
93
|
+
|
94
|
+
v_s = FlexMock.forbid_mocking("<recursive call to mocked method in #inspect>") do
|
95
|
+
v.inspect
|
96
|
+
end
|
97
|
+
"#{k_s}#{v_s}"
|
98
|
+
end
|
99
|
+
args.join(", ")
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
70
103
|
####################################################################
|
71
104
|
# Match objects that implement all the methods in +methods+.
|
72
105
|
class DuckMatcher
|
@@ -3,7 +3,8 @@ class FlexMock
|
|
3
3
|
# A composite expectation allows several expectations to be grouped into a
|
4
4
|
# single composite and then apply the same constraints to all expectations
|
5
5
|
# in the group.
|
6
|
-
class CompositeExpectation
|
6
|
+
class CompositeExpectation < BasicObject
|
7
|
+
attr_reader :expectations
|
7
8
|
|
8
9
|
# Initialize the composite expectation.
|
9
10
|
def initialize
|
@@ -97,6 +97,18 @@ class FlexMock
|
|
97
97
|
end
|
98
98
|
end
|
99
99
|
|
100
|
+
# Class method to format a list of args (the part between the
|
101
|
+
# parenthesis).
|
102
|
+
def format_kw_args(args)
|
103
|
+
if args
|
104
|
+
FlexMock.forbid_mocking("<recursive call to mocked method in #inspect>") do
|
105
|
+
args.inspect
|
106
|
+
end
|
107
|
+
else
|
108
|
+
"**args"
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
100
112
|
# Check will assert the block returns true. If it doesn't, an
|
101
113
|
# assertion failure is triggered with the given message.
|
102
114
|
def check(msg, &block) # :nodoc:
|
data/lib/flexmock/expectation.rb
CHANGED
@@ -65,6 +65,7 @@ class FlexMock
|
|
65
65
|
def description
|
66
66
|
result = ["should_receive(#{@sym.inspect})"]
|
67
67
|
result << ".with(#{FlexMock.format_args(@expected_args)})" if @expected_args
|
68
|
+
result << ".with_kw_args(#{FlexMock.format_kw_args(@expected_kw_args)})" if @expected_kw_args
|
68
69
|
@count_validators.each do |validator|
|
69
70
|
result << validator.describe
|
70
71
|
end
|
@@ -241,7 +242,12 @@ class FlexMock
|
|
241
242
|
# Declare that the method can be called with any number of
|
242
243
|
# arguments of any type.
|
243
244
|
def with_kw_args(matcher)
|
244
|
-
@expected_kw_args =
|
245
|
+
@expected_kw_args =
|
246
|
+
if matcher.kind_of?(Hash)
|
247
|
+
KwArgsMatcher.new(matcher)
|
248
|
+
else
|
249
|
+
matcher
|
250
|
+
end
|
245
251
|
self
|
246
252
|
end
|
247
253
|
|
data/lib/flexmock/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flexmock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.4.
|
4
|
+
version: 2.4.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jim Weirich
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2025-08-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: minitest
|