flexmock 2.3.8 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/flexmock.gemspec +1 -2
- data/lib/flexmock/core.rb +1 -1
- data/lib/flexmock/expectation.rb +77 -17
- data/lib/flexmock/expectation_builder.rb +1 -1
- data/lib/flexmock/expectation_director.rb +5 -3
- data/lib/flexmock/version.rb +1 -1
- metadata +3 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d0a8810418e4e6400b70c2704122d81e4a386f631f9013157429963b386fffa
|
4
|
+
data.tar.gz: ee80bbf1bcd0d626efa8d7a5512cfc7343c120d7123e83c16e10a35aad4f73c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d18374afda345a829ff9264901224891d8fcff4127415e9de3430209f8228cd43285ed79e70dae68b78f35c8affbace80d49767b68a490f67a655cd011bc8518
|
7
|
+
data.tar.gz: 2b49462130ee807ad062f382b1de1a9e3d25138efd41e2436ffbbaa9190581579f4c503e2eeadd86ec51e38887c7098558996814fc12d0f56f435d54e6266d8a
|
data/flexmock.gemspec
CHANGED
@@ -10,7 +10,7 @@ spec = Gem::Specification.new do |s|
|
|
10
10
|
interface is simple, it is very flexible.
|
11
11
|
}
|
12
12
|
|
13
|
-
s.required_ruby_version = ">= 2.
|
13
|
+
s.required_ruby_version = ">= 2.5"
|
14
14
|
|
15
15
|
s.license = 'MIT'
|
16
16
|
|
@@ -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
|
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,
|
@@ -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
|
|
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.0
|
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-08-20 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 "
|
@@ -179,7 +165,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
179
165
|
requirements:
|
180
166
|
- - ">="
|
181
167
|
- !ruby/object:Gem::Version
|
182
|
-
version: '2.
|
168
|
+
version: '2.5'
|
183
169
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
184
170
|
requirements:
|
185
171
|
- - ">="
|