flexmock 2.1.0 → 2.2.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/CHANGES +2 -0
- data/README.md +10 -2
- data/lib/flexmock/partial_mock.rb +49 -2
- data/lib/flexmock/version.rb +1 -1
- metadata +18 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 02acabaf029650f80ab19aed17459f6007aac4d8
|
4
|
+
data.tar.gz: 2efb9677abaeb434ec840ce5ad2d174101d333c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 210118eb5a0f18106cb0c3d9ba35b2db3792cbd694a7db7ded0aecebef98607cb5fe763f2e3a2607551b604960c10e820c6d5e3c94308e33430db0ca075bb453
|
7
|
+
data.tar.gz: 2abbd364c49ab6f5b392fbff175b15ee5ccb07602ce337530f68886e157940e0349a87ffc696affa2877fd821985bbdd522a406b5c0e2239b34958a4ad5c5457
|
data/CHANGES
CHANGED
data/README.md
CHANGED
@@ -22,6 +22,14 @@ 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.2.0:
|
26
|
+
|
27
|
+
- #new_instances now mocks the #initialize method instead of mocking after the
|
28
|
+
allocation was done. This allows to do mock methods called by #initialize
|
29
|
+
itself. Behaviour when the allocator is explicitely provided is left
|
30
|
+
unchanged, which means that the old behaviour is still available by passing
|
31
|
+
:new to new_instances.
|
32
|
+
|
25
33
|
2.1.0:
|
26
34
|
|
27
35
|
- added `#and_iterates` to fix some shortcomings of `#and_yield` without
|
@@ -916,7 +924,7 @@ MiniTest for asserting that mocked methods are actually called.
|
|
916
924
|
Specify the number of times a matching method should have been
|
917
925
|
invoked. `nil` (or omitted) means any number of times.
|
918
926
|
|
919
|
-
* <b>with_block: <em>true/false/nil</em>
|
927
|
+
* <b>with_block: <em>true/false/nil</em></b>
|
920
928
|
|
921
929
|
Is a block required on the invocation? `true` means the method must
|
922
930
|
be invoked with a block. `false` means the method must have been
|
@@ -972,7 +980,7 @@ spy behavior.
|
|
972
980
|
|
973
981
|
*Modifiers for `have_received`*
|
974
982
|
|
975
|
-
* <b>with(<em>args</em>)
|
983
|
+
* <b>with(<em>args</em>)</b>
|
976
984
|
|
977
985
|
If a `with` modifier is given, only messages with matching arguments
|
978
986
|
are considered. _args_ can be any of the argument matches mentioned
|
@@ -68,6 +68,7 @@ class FlexMock
|
|
68
68
|
@method_definitions = {}
|
69
69
|
@methods_proxied = []
|
70
70
|
@proxy_definition_module = nil
|
71
|
+
@initialize_override = nil
|
71
72
|
unless safe_mode
|
72
73
|
add_mock_method(:should_receive)
|
73
74
|
MOCK_METHODS.each do |sym|
|
@@ -156,8 +157,14 @@ class FlexMock
|
|
156
157
|
fail ArgumentError, "new_instances requires a Class to stub" unless
|
157
158
|
Class === @obj
|
158
159
|
location = caller
|
159
|
-
allocators = [:
|
160
|
+
allocators = [:initialize] if allocators.empty?
|
161
|
+
|
160
162
|
expectation_recorder = ExpectationRecorder.new
|
163
|
+
|
164
|
+
if allocators.delete(:initialize)
|
165
|
+
initialize_stub(expectation_recorder, block)
|
166
|
+
end
|
167
|
+
|
161
168
|
allocators.each do |allocate_method|
|
162
169
|
flexmock_define_expectation(location, allocate_method).and_return { |*args|
|
163
170
|
create_new_mocked_object(
|
@@ -167,6 +174,45 @@ class FlexMock
|
|
167
174
|
expectation_recorder
|
168
175
|
end
|
169
176
|
|
177
|
+
# Stubs the #initialize method on a class
|
178
|
+
def initialize_stub(recorder, expectations_block)
|
179
|
+
if !@initialize_override
|
180
|
+
expectation_blocks = @initialize_expectation_blocks = Array.new
|
181
|
+
expectation_recorders = @initialize_expectation_recorders = Array.new
|
182
|
+
@initialize_override = Module.new do
|
183
|
+
define_method :initialize do |*args, &block|
|
184
|
+
if self.class.respond_to?(:__flexmock_proxy) && (mock = self.class.__flexmock_proxy)
|
185
|
+
container = mock.flexmock_container
|
186
|
+
mock = container.flexmock(self)
|
187
|
+
expectation_blocks.each do |b|
|
188
|
+
b.call(mock)
|
189
|
+
end
|
190
|
+
expectation_recorders.each do |r|
|
191
|
+
r.apply(mock)
|
192
|
+
end
|
193
|
+
end
|
194
|
+
super(*args, &block)
|
195
|
+
end
|
196
|
+
end
|
197
|
+
@obj.prepend @initialize_override
|
198
|
+
end
|
199
|
+
if expectations_block
|
200
|
+
@initialize_expectation_blocks << expectations_block
|
201
|
+
end
|
202
|
+
@initialize_expectation_recorders << recorder
|
203
|
+
end
|
204
|
+
|
205
|
+
def initialize_stub?
|
206
|
+
!!@initialize_override
|
207
|
+
end
|
208
|
+
|
209
|
+
def initialize_stub_remove
|
210
|
+
if initialize_stub?
|
211
|
+
@initialize_expectation_blocks.clear
|
212
|
+
@initialize_expectation_recorders.clear
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
170
216
|
# Create a new mocked object.
|
171
217
|
#
|
172
218
|
# The mocked object is created using the following steps:
|
@@ -206,6 +252,7 @@ class FlexMock
|
|
206
252
|
# Remove all traces of the mocking framework from the existing object.
|
207
253
|
def flexmock_teardown
|
208
254
|
if ! detached?
|
255
|
+
initialize_stub_remove
|
209
256
|
proxy_module_eval do
|
210
257
|
methods = instance_methods(false).to_a
|
211
258
|
methods.each do |m|
|
@@ -268,7 +315,7 @@ class FlexMock
|
|
268
315
|
if !@proxy_definition_module
|
269
316
|
obj = @obj
|
270
317
|
@proxy_definition_module = m = Module.new do
|
271
|
-
define_method(
|
318
|
+
define_method("__flexmock_proxy") do
|
272
319
|
if box = obj.instance_variable_get(:@flexmock_proxy)
|
273
320
|
box.proxy
|
274
321
|
end
|
data/lib/flexmock/version.rb
CHANGED
metadata
CHANGED
@@ -1,75 +1,75 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flexmock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jim Weirich
|
8
8
|
- Sylvain Joyeux
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-07-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
+
name: minitest
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
16
17
|
requirements:
|
17
18
|
- - ">="
|
18
19
|
- !ruby/object:Gem::Version
|
19
20
|
version: '0'
|
20
|
-
name: minitest
|
21
|
-
prerelease: false
|
22
21
|
type: :development
|
22
|
+
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - ">="
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: '0'
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
29
30
|
requirement: !ruby/object:Gem::Requirement
|
30
31
|
requirements:
|
31
32
|
- - ">="
|
32
33
|
- !ruby/object:Gem::Version
|
33
34
|
version: '0'
|
34
|
-
name: rake
|
35
|
-
prerelease: false
|
36
35
|
type: :development
|
36
|
+
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
39
|
- - ">="
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: '0'
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
|
+
name: simplecov
|
43
44
|
requirement: !ruby/object:Gem::Requirement
|
44
45
|
requirements:
|
45
46
|
- - ">="
|
46
47
|
- !ruby/object:Gem::Version
|
47
48
|
version: 0.11.0
|
48
|
-
name: simplecov
|
49
|
-
prerelease: false
|
50
49
|
type: :development
|
50
|
+
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
53
|
- - ">="
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: 0.11.0
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
|
+
name: coveralls
|
57
58
|
requirement: !ruby/object:Gem::Requirement
|
58
59
|
requirements:
|
59
60
|
- - ">="
|
60
61
|
- !ruby/object:Gem::Version
|
61
62
|
version: '0'
|
62
|
-
name: coveralls
|
63
|
-
prerelease: false
|
64
63
|
type: :development
|
64
|
+
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
67
|
- - ">="
|
68
68
|
- !ruby/object:Gem::Version
|
69
69
|
version: '0'
|
70
|
-
description: "\n FlexMock is a extremely simple mock object class compatible\n
|
71
|
-
\
|
72
|
-
|
70
|
+
description: "\n FlexMock is a extremely simple mock object class compatible\n
|
71
|
+
\ with the Minitest framework. Although the FlexMock's\n interface is simple,
|
72
|
+
it is very flexible.\n "
|
73
73
|
email: sylvain.joyeux@m4x.org
|
74
74
|
executables: []
|
75
75
|
extensions: []
|
@@ -169,7 +169,7 @@ homepage: https://github.com/doudou/flexmock
|
|
169
169
|
licenses:
|
170
170
|
- MIT
|
171
171
|
metadata: {}
|
172
|
-
post_install_message:
|
172
|
+
post_install_message:
|
173
173
|
rdoc_options: []
|
174
174
|
require_paths:
|
175
175
|
- lib
|
@@ -184,9 +184,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
184
184
|
- !ruby/object:Gem::Version
|
185
185
|
version: '0'
|
186
186
|
requirements: []
|
187
|
-
rubyforge_project:
|
188
|
-
rubygems_version: 2.
|
189
|
-
signing_key:
|
187
|
+
rubyforge_project:
|
188
|
+
rubygems_version: 2.5.1
|
189
|
+
signing_key:
|
190
190
|
specification_version: 4
|
191
191
|
summary: Simple and Flexible Mock Objects for Testing
|
192
192
|
test_files: []
|