crispy 0.3.0 → 0.3.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/ChangeLog.md +6 -1
- data/README.md +14 -1
- data/lib/crispy/crispy_internal/class_spy.rb +4 -0
- data/lib/crispy/crispy_internal/spy.rb +17 -0
- data/lib/crispy/crispy_internal/spy_base.rb +9 -8
- data/lib/crispy/crispy_world.rb +2 -0
- data/lib/crispy/version.rb +1 -1
- data/test/doctest-fixtures/your_cool_class.rb +2 -0
- data/test/test_crispy.rb +34 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f0ba38b20d7b6e7700337f66b764927162119554
|
4
|
+
data.tar.gz: 010fb0e6c5a5ca038d34233e183765d48e0ba4fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 998646e708b914e987754ac308f65fd941f832f3ca0859dff0232651f195dabca73075bf66e2d3b875bc80741665053910b262ff2e5ba111a09d7b5ba7013992
|
7
|
+
data.tar.gz: 7e00aba14ee6804286283d024e8a568e40d01ba0eb2df9bcc7c11c0267247a3071281b7667bc5d350e561803d24b95a0744934d358d5ca3e541504e978b2b20f
|
data/ChangeLog.md
CHANGED
@@ -1,8 +1,13 @@
|
|
1
|
+
# 0.3.1 (2015.1.3)
|
2
|
+
|
3
|
+
- Enhancement: Forget every spy log and reset every stubbed method by resetting. [#25](https://github.com/igrep/crispy/pull/25)
|
4
|
+
- Fix bug: Not spied anymore after removing the stubbed methods when resetting. [`cb38ddf`](https://github.com/igrep/crispy/commit/cb38ddf6f0affe2ea884e4a16d7622dca51c1f2d)
|
5
|
+
|
1
6
|
# 0.3.0 (2014.12.31)
|
2
7
|
|
3
8
|
- New Feature: Add stub feature to `ClassSpy`. [#23](https://github.com/igrep/crispy/pull/23)
|
4
9
|
- New Feature: Now double is automatically spied without `spy_into`. [#21](https://github.com/igrep/crispy/pull/21)
|
5
|
-
- Fix Bug: now `spy_into` replaces all stubber's methods with given stub spec when reinitialize a spy.[
|
10
|
+
- Fix Bug: now `spy_into` replaces all stubber's methods with given stub spec when reinitialize a spy. [`0f9157`](https://github.com/igrep/crispy/commit/0f91579decbe27e6b05bec4b779dd1c3ede24380)
|
6
11
|
- Fix Bug: reset spy log when `spy_into`-ing an already spied object. e.g. Class.[#20](https://github.com/igrep/crispy/pull/20)
|
7
12
|
- New Feature: `spied?`. [#18](https://github.com/igrep/crispy/pull/18)
|
8
13
|
- Refactor many internal classes and tests. [#21](https://github.com/igrep/crispy/pull/21) [#22](https://github.com/igrep/crispy/pull/22) [#23](https://github.com/igrep/crispy/pull/23) [#24](https://github.com/igrep/crispy/pull/24)
|
data/README.md
CHANGED
@@ -268,11 +268,24 @@ Specify the **fully qualified name of the constant** instead of the constant its
|
|
268
268
|
=> "more cool value!"
|
269
269
|
```
|
270
270
|
|
271
|
-
|
271
|
+
### Embedding Crispy into your Testing Framework
|
272
|
+
|
273
|
+
Remember to reset all the changes made by Crispy, call `CrispyWorld.reset`.
|
272
274
|
|
273
275
|
```ruby
|
274
276
|
>> CrispyWorld.reset
|
275
277
|
|
278
|
+
>> spy(object).count_received :your_cool_method
|
279
|
+
=> 0
|
280
|
+
>> spy(object).count_received :your_lovely_method
|
281
|
+
=> 0
|
282
|
+
>> spy(object).received? :your_finalizer
|
283
|
+
=> false
|
284
|
+
|
285
|
+
>> object.your_cool_method
|
286
|
+
=> "cool!"
|
287
|
+
>> object.your_lovely_method
|
288
|
+
=> "lovely!"
|
276
289
|
>> YourCoolClass::YOUR_COOL_CONST
|
277
290
|
=> "value before stubbed"
|
278
291
|
```
|
@@ -1,10 +1,14 @@
|
|
1
1
|
require 'crispy/crispy_received_message'
|
2
2
|
require 'crispy/crispy_internal/spy_base'
|
3
3
|
|
4
|
+
require 'weakref'
|
5
|
+
|
4
6
|
module Crispy
|
5
7
|
module CrispyInternal
|
6
8
|
class Spy < SpyBase
|
7
9
|
|
10
|
+
@spies_to_reset = []
|
11
|
+
|
8
12
|
attr_reader :received_messages
|
9
13
|
|
10
14
|
def initialize target, stubs_map = {}
|
@@ -15,6 +19,8 @@ module Crispy
|
|
15
19
|
|
16
20
|
@received_messages = []
|
17
21
|
super
|
22
|
+
|
23
|
+
self.class.remember_to_reset_later self
|
18
24
|
end
|
19
25
|
|
20
26
|
def target_to_class target
|
@@ -37,6 +43,17 @@ module Crispy
|
|
37
43
|
end
|
38
44
|
private :append_received_message
|
39
45
|
|
46
|
+
def self.remember_to_reset_later spy
|
47
|
+
@spies_to_reset << ::WeakRef.new(spy)
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.reset_all
|
51
|
+
# get rid of spies of GCed objects
|
52
|
+
@spies_to_reset.select! {|spy| spy.weakref_alive? }
|
53
|
+
|
54
|
+
@spies_to_reset.each {|spy| spy.reinitialize }
|
55
|
+
end
|
56
|
+
|
40
57
|
end
|
41
58
|
end
|
42
59
|
end
|
@@ -21,14 +21,7 @@ module Crispy
|
|
21
21
|
|
22
22
|
def self.new target, stubs_map = {}
|
23
23
|
spy = self.of_target(target)
|
24
|
-
|
25
|
-
spy.restart
|
26
|
-
spy.erase_log
|
27
|
-
spy.reinitialize_stubber stubs_map
|
28
|
-
spy
|
29
|
-
else
|
30
|
-
super
|
31
|
-
end
|
24
|
+
spy ? spy.reinitialize(stubs_map) : super
|
32
25
|
end
|
33
26
|
|
34
27
|
def self.of_target target
|
@@ -51,6 +44,13 @@ module Crispy
|
|
51
44
|
raise NotImplementedError
|
52
45
|
end
|
53
46
|
|
47
|
+
def reinitialize stubs_map = {}
|
48
|
+
restart
|
49
|
+
erase_log
|
50
|
+
reinitialize_stubber stubs_map
|
51
|
+
self
|
52
|
+
end
|
53
|
+
|
54
54
|
def stop
|
55
55
|
@spying = false
|
56
56
|
end
|
@@ -126,6 +126,7 @@ module Crispy
|
|
126
126
|
|
127
127
|
def reinitialize_stubber stubs_map = {}
|
128
128
|
remove_method(*@stubbed_methods)
|
129
|
+
@stubbed_methods.each {|stubbed_method| define_wrapper stubbed_method }
|
129
130
|
@stubbed_methods.clear
|
130
131
|
stub stubs_map
|
131
132
|
end
|
data/lib/crispy/crispy_world.rb
CHANGED
data/lib/crispy/version.rb
CHANGED
data/test/test_crispy.rb
CHANGED
@@ -226,6 +226,24 @@ class TestCrispy < MiniTest::Test
|
|
226
226
|
assert_equal 'xxx' , ObjectClass.stubbed_method3
|
227
227
|
end
|
228
228
|
|
229
|
+
def test_spy_resets_stubbed_methods_after_resetting
|
230
|
+
CrispyWorld.reset
|
231
|
+
assert_equal 'before stubbed 1', ObjectClass.stubbed_method1
|
232
|
+
assert_equal 'before stubbed 2', ObjectClass.stubbed_method2
|
233
|
+
end
|
234
|
+
|
235
|
+
def test_spy_forgets_received_messages_after_resetting
|
236
|
+
CrispyWorld.reset
|
237
|
+
assert_empty @subject.received_messages
|
238
|
+
end
|
239
|
+
|
240
|
+
def test_spy_still_logs_methods_stubbed_once_after_resetting
|
241
|
+
CrispyWorld.reset
|
242
|
+
|
243
|
+
ObjectClass.stubbed_method1
|
244
|
+
assert_equal 1, spy(ObjectClass).count_received(:stubbed_method1)
|
245
|
+
end
|
246
|
+
|
229
247
|
end
|
230
248
|
|
231
249
|
class TestCrispySpyIntoInstances < TestCrispy
|
@@ -274,6 +292,22 @@ class TestCrispy < MiniTest::Test
|
|
274
292
|
end
|
275
293
|
end
|
276
294
|
|
295
|
+
def test_spy_resets_stubbed_methods_after_resetting
|
296
|
+
::Crispy::CrispyWorld.reset
|
297
|
+
|
298
|
+
@object_instances.each do|object|
|
299
|
+
assert_equal 'method to stub 1 (before stubbed)', object.method_to_stub1
|
300
|
+
assert_equal 'method to stub 2 (before stubbed)', object.method_to_stub2
|
301
|
+
assert_equal 'method to stub 3 (before stubbed)', object.method_to_stub3
|
302
|
+
end
|
303
|
+
end
|
304
|
+
|
305
|
+
def test_spy_forgets_received_messages_after_resetting
|
306
|
+
::Crispy::CrispyWorld.reset
|
307
|
+
assert_empty @subject.received_messages
|
308
|
+
assert_empty @subject.received_messages_with_receiver
|
309
|
+
end
|
310
|
+
|
277
311
|
end
|
278
312
|
|
279
313
|
class TestReceivedMessage < self
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: crispy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yamamoto Yuji
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|