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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 55630790b40e21c94d842f9b5a173f0a3e2535aa40c4cc23c00aaaedaeaeb31a
4
- data.tar.gz: 2afc06542cbe3ef561fb51239ccdfd646e677ee5508038d7532fe427049713f8
3
+ metadata.gz: 95477346c9b4f5310e7aab502150273b0473194442fdee505ab366efbbba77bf
4
+ data.tar.gz: cf44602d7ddfa3197ff847e476da46adc9b82a07382c100e2eb149abc56ae285
5
5
  SHA512:
6
- metadata.gz: e41731de6baa727d4580e5033180becda98c24a9b0522bf41a802f133023e20d6052c2d4a812ee435204cc8159bfdab32d3ddc66922ba8a69b8bf4427e89e13e
7
- data.tar.gz: fc31b71f78372d05cc3e44e7648d9a5c8c9f7499ac56a4713e63eb1a3db4ba4f9b2107ae989cf967d44e0206e0f8e134ec675821c3710248952835daa8e1b457
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:
@@ -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 = matcher
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
 
@@ -34,7 +34,7 @@ class FlexMock
34
34
  def apply(mock)
35
35
  obj = mock
36
36
  @expectations.each do |sym, args, block|
37
- obj = obj.send(sym, *args, &block)
37
+ obj = obj.__send__(sym, *args, &block)
38
38
  end
39
39
  end
40
40
  end
@@ -287,6 +287,7 @@ class FlexMock
287
287
  r.apply(mock)
288
288
  end
289
289
  end
290
+ # Workaround kw arg support for ruby < 2.7
290
291
  super(*args, &block)
291
292
  end
292
293
  end
@@ -1,3 +1,3 @@
1
1
  class FlexMock
2
- VERSION = "2.4.2"
2
+ VERSION = "2.4.5"
3
3
  end
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.2
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: 2024-09-16 00:00:00.000000000 Z
12
+ date: 2025-08-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: minitest