flexmock 2.3.8 → 2.4.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/flexmock.gemspec +0 -1
- data/lib/flexmock/core.rb +2 -2
- data/lib/flexmock/expectation.rb +79 -19
- data/lib/flexmock/expectation_builder.rb +1 -1
- data/lib/flexmock/expectation_director.rb +5 -3
- data/lib/flexmock/partial_mock.rb +3 -10
- data/lib/flexmock/version.rb +1 -1
- metadata +2 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bed75deb751a06729f5fd1b31ce17b9568fc959cb74b49d6f1291c0de1a53cb7
|
4
|
+
data.tar.gz: c7c34401a7d5166ce476b36ca94ceba4789b4c77437f71c2e8f1d00afe3803df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c638316ab0058cea04174eaecc228352bc7710935d57d230362908ed86854fcb53e9aa0236d1003a0d0ebaeeecaa34a7735db20a15e40862242f7aecbcde88b2
|
7
|
+
data.tar.gz: c9cd6ea00208e8a7cb0e9d3855886fd2776e8f0d7b60a2fb4a3521ab1051db3d37ea435c44b538215618498197276e83158e05a7b6ea36e29df66c9cac265a5c
|
data/flexmock.gemspec
CHANGED
@@ -19,7 +19,6 @@ spec = Gem::Specification.new do |s|
|
|
19
19
|
s.add_development_dependency 'minitest', ">= 5.0"
|
20
20
|
s.add_development_dependency 'rake'
|
21
21
|
s.add_development_dependency 'simplecov', '>= 0.11.0'
|
22
|
-
s.add_development_dependency 'coveralls'
|
23
22
|
|
24
23
|
#### Which files are to be included in this gem? Everything! (Except CVS directories.)
|
25
24
|
|
data/lib/flexmock/core.rb
CHANGED
@@ -147,7 +147,7 @@ class FlexMock
|
|
147
147
|
if flexmock_closed?
|
148
148
|
FlexMock.undefined
|
149
149
|
elsif exp = flexmock_expectations_for(sym)
|
150
|
-
exp.call(
|
150
|
+
exp.call(args, block, call_record)
|
151
151
|
elsif @base_class && @base_class.flexmock_defined?(sym)
|
152
152
|
FlexMock.undefined
|
153
153
|
elsif @ignore_missing
|
@@ -207,7 +207,7 @@ class FlexMock
|
|
207
207
|
|
208
208
|
# Invocke the original non-mocked functionality for the given
|
209
209
|
# symbol.
|
210
|
-
def flexmock_invoke_original(method_name, args)
|
210
|
+
def flexmock_invoke_original(method_name, args, orig_block)
|
211
211
|
return FlexMock.undefined
|
212
212
|
end
|
213
213
|
|
data/lib/flexmock/expectation.rb
CHANGED
@@ -37,6 +37,8 @@ class FlexMock
|
|
37
37
|
@sym = sym
|
38
38
|
@location = location
|
39
39
|
@expected_args = nil
|
40
|
+
@expected_kw_args = nil
|
41
|
+
@expected_block = nil
|
40
42
|
@count_validators = []
|
41
43
|
@signature_validator = SignatureValidator.new(self)
|
42
44
|
@count_validator_class = ExactCountValidator
|
@@ -61,7 +63,7 @@ class FlexMock
|
|
61
63
|
# * call count validators
|
62
64
|
#
|
63
65
|
def description
|
64
|
-
result = "should_receive(#{@sym.inspect})"
|
66
|
+
result = ["should_receive(#{@sym.inspect})"]
|
65
67
|
result << ".with(#{FlexMock.format_args(@expected_args)})" if @expected_args
|
66
68
|
@count_validators.each do |validator|
|
67
69
|
result << validator.describe
|
@@ -69,7 +71,7 @@ class FlexMock
|
|
69
71
|
if !@signature_validator.null?
|
70
72
|
result << @signature_validator.describe
|
71
73
|
end
|
72
|
-
result
|
74
|
+
result.join
|
73
75
|
end
|
74
76
|
|
75
77
|
# Validate that this expectation is eligible for an extra call
|
@@ -91,42 +93,55 @@ class FlexMock
|
|
91
93
|
|
92
94
|
# Verify the current call with the given arguments matches the
|
93
95
|
# expectations recorded in this object.
|
94
|
-
def verify_call(*args)
|
96
|
+
def verify_call(*args, &block)
|
95
97
|
validate_eligible
|
96
98
|
validate_order
|
97
|
-
|
99
|
+
enhanced_args =
|
100
|
+
if block
|
101
|
+
args + [block]
|
102
|
+
else
|
103
|
+
args
|
104
|
+
end
|
105
|
+
|
106
|
+
validate_signature(enhanced_args)
|
98
107
|
@actual_count += 1
|
99
|
-
perform_yielding(args)
|
100
|
-
return_value(args)
|
108
|
+
perform_yielding(args, block)
|
109
|
+
return_value(args, block)
|
101
110
|
end
|
102
111
|
|
103
112
|
# Public return value (odd name to avoid accidental use as a
|
104
113
|
# constraint).
|
105
|
-
def _return_value(args) # :nodoc:
|
106
|
-
return_value(args)
|
114
|
+
def _return_value(args, block) # :nodoc:
|
115
|
+
return_value(args, block)
|
107
116
|
end
|
108
117
|
|
109
118
|
# Find the return value for this expectation. (private version)
|
110
|
-
def return_value(args)
|
119
|
+
def return_value(args, block)
|
111
120
|
case @return_queue.size
|
112
121
|
when 0
|
113
|
-
|
122
|
+
ret_block = lambda { |*a| @return_value }
|
114
123
|
when 1
|
115
|
-
|
124
|
+
ret_block = @return_queue.first
|
116
125
|
else
|
117
|
-
|
126
|
+
ret_block = @return_queue.shift
|
127
|
+
end
|
128
|
+
|
129
|
+
if @expected_block
|
130
|
+
ret_block.call(*args, &block)
|
131
|
+
elsif block
|
132
|
+
ret_block.call(*args, block)
|
133
|
+
else
|
134
|
+
ret_block.call(*args)
|
118
135
|
end
|
119
|
-
block.call(*args)
|
120
136
|
end
|
121
137
|
private :return_value
|
122
138
|
|
123
139
|
# Yield stored values to any blocks given.
|
124
|
-
def perform_yielding(args)
|
140
|
+
def perform_yielding(args, block)
|
125
141
|
@return_value = nil
|
126
142
|
unless @yield_queue.empty?
|
127
|
-
block = args.last
|
128
143
|
values = (@yield_queue.size == 1) ? @yield_queue.first : @yield_queue.shift
|
129
|
-
if block
|
144
|
+
if block
|
130
145
|
values.each do |v|
|
131
146
|
@return_value = block.call(*v)
|
132
147
|
end
|
@@ -171,7 +186,38 @@ class FlexMock
|
|
171
186
|
# Does the argument list match this expectation's argument
|
172
187
|
# specification.
|
173
188
|
def match_args(args)
|
174
|
-
|
189
|
+
expected_args =
|
190
|
+
if @expected_kw_args
|
191
|
+
if proc_matcher?(@expected_args&.last) && @expected_block.nil?
|
192
|
+
@expected_args[0..-2] + [@expected_kw_args, @expected_args[-1]]
|
193
|
+
else
|
194
|
+
(@expected_args || []) + [@expected_kw_args]
|
195
|
+
end
|
196
|
+
else
|
197
|
+
@expected_args
|
198
|
+
end
|
199
|
+
|
200
|
+
if @expected_block
|
201
|
+
expected_args = (expected_args || []) + [@expected_block]
|
202
|
+
end
|
203
|
+
|
204
|
+
ArgumentMatching.all_match?(expected_args, args)
|
205
|
+
end
|
206
|
+
|
207
|
+
def proc_matcher?(obj)
|
208
|
+
obj == Proc || obj == OPTIONAL_PROC_MATCHER
|
209
|
+
end
|
210
|
+
|
211
|
+
def with_optional_block
|
212
|
+
@expected_block = OPTIONAL_PROC_MATCHER
|
213
|
+
end
|
214
|
+
|
215
|
+
def with_block
|
216
|
+
@expected_block = Proc
|
217
|
+
end
|
218
|
+
|
219
|
+
def with_no_block
|
220
|
+
@expected_block = false
|
175
221
|
end
|
176
222
|
|
177
223
|
# Declare that the method should expect the given argument list.
|
@@ -192,6 +238,20 @@ class FlexMock
|
|
192
238
|
self
|
193
239
|
end
|
194
240
|
|
241
|
+
# Declare that the method can be called with any number of
|
242
|
+
# arguments of any type.
|
243
|
+
def with_kw_args(matcher)
|
244
|
+
@expected_kw_args = matcher
|
245
|
+
self
|
246
|
+
end
|
247
|
+
|
248
|
+
# Declare that the method can be called with any number of
|
249
|
+
# arguments of any type.
|
250
|
+
def with_any_kw_args
|
251
|
+
@expected_kw_args = FlexMock.any
|
252
|
+
self
|
253
|
+
end
|
254
|
+
|
195
255
|
# Validate general parameters on the call signature
|
196
256
|
def with_signature(
|
197
257
|
required_arguments: 0, optional_arguments: 0, splat: false,
|
@@ -345,9 +405,9 @@ class FlexMock
|
|
345
405
|
|
346
406
|
def pass_thru(&block)
|
347
407
|
block ||= lambda { |value| value }
|
348
|
-
and_return { |*args|
|
408
|
+
and_return { |*args, &orig_block|
|
349
409
|
begin
|
350
|
-
block.call(@mock.flexmock_invoke_original(@sym, args))
|
410
|
+
block.call(@mock.flexmock_invoke_original(@sym, args, orig_block))
|
351
411
|
rescue NoMethodError => e
|
352
412
|
if e.name == @sym
|
353
413
|
raise e, "#{e.message} while performing #pass_thru in expectation object #{self}"
|
@@ -86,7 +86,7 @@ class FlexMock
|
|
86
86
|
names.each do |name|
|
87
87
|
exp = mock.flexmock_find_expectation(name)
|
88
88
|
if exp
|
89
|
-
next_mock = exp._return_value([])
|
89
|
+
next_mock = exp._return_value([], nil)
|
90
90
|
check_proper_mock(next_mock, name)
|
91
91
|
else
|
92
92
|
next_mock = container.flexmock("demeter_#{name}")
|
@@ -35,8 +35,10 @@ class FlexMock
|
|
35
35
|
# but at least we will get a good failure message). Finally,
|
36
36
|
# check for expectations that don't have any argument matching
|
37
37
|
# criteria.
|
38
|
-
def call(args, call_record=nil)
|
39
|
-
|
38
|
+
def call(args, block = nil, call_record=nil)
|
39
|
+
find_args = args.dup
|
40
|
+
find_args << block if block
|
41
|
+
exp = find_expectation(*find_args)
|
40
42
|
call_record.expectation = exp if call_record
|
41
43
|
FlexMock.check(
|
42
44
|
proc { "no matching handler found for " +
|
@@ -44,7 +46,7 @@ class FlexMock
|
|
44
46
|
"\nDefined expectations:\n " +
|
45
47
|
@expectations.map(&:description).join("\n ") }
|
46
48
|
) { !exp.nil? }
|
47
|
-
returned_value = exp.verify_call(*args)
|
49
|
+
returned_value = exp.verify_call(*args, &block)
|
48
50
|
returned_value
|
49
51
|
end
|
50
52
|
|
@@ -162,10 +162,7 @@ class FlexMock
|
|
162
162
|
#
|
163
163
|
# Usually called in a #and_return statement
|
164
164
|
def invoke_original(m, *args, &block)
|
165
|
-
|
166
|
-
args << block
|
167
|
-
end
|
168
|
-
flexmock_invoke_original(m, args)
|
165
|
+
flexmock_invoke_original(m, args, block)
|
169
166
|
end
|
170
167
|
|
171
168
|
# Whether the given method's original definition has been stored
|
@@ -321,7 +318,7 @@ class FlexMock
|
|
321
318
|
# (3) Apply any recorded expecations
|
322
319
|
#
|
323
320
|
def create_new_mocked_object(allocate_method, args, recorder, block)
|
324
|
-
new_obj = flexmock_invoke_original(allocate_method, args)
|
321
|
+
new_obj = flexmock_invoke_original(allocate_method, args, nil)
|
325
322
|
mock = flexmock_container.flexmock(new_obj)
|
326
323
|
block.call(mock) unless block.nil?
|
327
324
|
recorder.apply(mock)
|
@@ -331,12 +328,8 @@ class FlexMock
|
|
331
328
|
|
332
329
|
# Invoke the original definition of method on the object supported by
|
333
330
|
# the stub.
|
334
|
-
def flexmock_invoke_original(method, args)
|
331
|
+
def flexmock_invoke_original(method, args, block)
|
335
332
|
if (original_method = find_original_method(method))
|
336
|
-
if Proc === args.last
|
337
|
-
block = args.last
|
338
|
-
args = args[0..-2]
|
339
|
-
end
|
340
333
|
original_method.call(*args, &block)
|
341
334
|
else
|
342
335
|
@obj.__send__(:method_missing, method, *args, &block)
|
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
|
+
version: 2.4.1
|
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: 2024-09-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: minitest
|
@@ -53,20 +53,6 @@ dependencies:
|
|
53
53
|
- - ">="
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: 0.11.0
|
56
|
-
- !ruby/object:Gem::Dependency
|
57
|
-
name: coveralls
|
58
|
-
requirement: !ruby/object:Gem::Requirement
|
59
|
-
requirements:
|
60
|
-
- - ">="
|
61
|
-
- !ruby/object:Gem::Version
|
62
|
-
version: '0'
|
63
|
-
type: :development
|
64
|
-
prerelease: false
|
65
|
-
version_requirements: !ruby/object:Gem::Requirement
|
66
|
-
requirements:
|
67
|
-
- - ">="
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
version: '0'
|
70
56
|
description: "\n FlexMock is a extremely simple mock object class compatible\n
|
71
57
|
\ with the Minitest framework. Although the FlexMock's\n interface is simple,
|
72
58
|
it is very flexible.\n "
|