spy_rb 0.5.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/spy/instance/api/internal.rb +43 -28
- data/lib/spy/instance.rb +4 -0
- data/lib/spy/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fb54969a1052380817f46a078bf3ebafe57acb2c
|
4
|
+
data.tar.gz: e29c5522dfd48423fe78b387fc06ce29e005d16d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e415ad43572895dc1e3d94f25e61690b2b143fc32ac6fcdc581258b218db44eef37425afd44e0c05ea0ee5ab6e87e03e938ee4ced101eacb592ed625ffe2089f
|
7
|
+
data.tar.gz: ff2432d2149adacf34bd528f6b5ea62464eff36dc6d5eeb429431d254977893079062cb74b9f322f0230098df1e96fc3846053a42398f834bd495298b23a2b1b
|
@@ -28,48 +28,63 @@ module Spy
|
|
28
28
|
# This will let us be a bit more elegant about how we do before/after
|
29
29
|
# callbacks. We can also merge MethodCall with this responsibility so
|
30
30
|
# it isn't just a data struct
|
31
|
-
is_active = @conditional_filters.
|
31
|
+
is_active = if @conditional_filters.any?
|
32
|
+
mc = build_method_call(receiver, *args, &block)
|
33
|
+
@conditional_filters.all? {|f| f.call(mc)}
|
34
|
+
else
|
35
|
+
true
|
36
|
+
end
|
32
37
|
|
33
|
-
if !is_active
|
34
|
-
|
35
|
-
|
36
|
-
|
38
|
+
return call_original(receiver, *args, &block) if !is_active
|
39
|
+
|
40
|
+
if @before_callbacks.any?
|
41
|
+
mc = build_method_call(receiver, *args, &block)
|
42
|
+
@before_callbacks.each {|f| f.call(mc)}
|
43
|
+
end
|
37
44
|
|
38
|
-
|
39
|
-
|
40
|
-
# Still return the result from it
|
41
|
-
result = nil
|
42
|
-
original_proc = Proc.new do
|
43
|
-
result = call_and_record(receiver, *args, &block)
|
44
|
-
end
|
45
|
+
if @around_procs.any?
|
46
|
+
mc = build_method_call(receiver, *args, &block)
|
45
47
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
result = call_and_record(receiver, *args, &block)
|
48
|
+
# Procify the original call
|
49
|
+
# Still return the result from it
|
50
|
+
result = nil
|
51
|
+
original_proc = Proc.new do
|
52
|
+
result = call_and_record(receiver, args, { :record => mc }, &block)
|
52
53
|
end
|
53
54
|
|
54
|
-
|
55
|
+
# Keep wrapping the original proc with each around_proc
|
56
|
+
@around_procs.reduce(original_proc) do |p, wrapper|
|
57
|
+
Proc.new { wrapper.call(mc, &p) }
|
58
|
+
end.call
|
59
|
+
else
|
60
|
+
result = call_and_record(receiver, args, &block)
|
61
|
+
end
|
55
62
|
|
56
|
-
|
63
|
+
if @after_callbacks.any?
|
64
|
+
mc = @call_history.last
|
65
|
+
@after_callbacks.each {|f| f.call(mc)}
|
57
66
|
end
|
67
|
+
|
68
|
+
result
|
58
69
|
end
|
59
70
|
|
60
71
|
private
|
61
72
|
|
62
|
-
def
|
63
|
-
|
64
|
-
|
65
|
-
|
73
|
+
def build_method_call(receiver, *args, &block)
|
74
|
+
Spy::MethodCall.new(
|
75
|
+
proc { call_original(receiver, *args, &block) },
|
76
|
+
original.name,
|
77
|
+
receiver,
|
78
|
+
*args,
|
79
|
+
&block)
|
66
80
|
end
|
67
81
|
|
68
|
-
def
|
69
|
-
|
70
|
-
record = Spy::MethodCall.new(replayer, original.name, receiver, *args, &block)
|
82
|
+
def call_and_record(receiver, args, opts = {}, &block)
|
83
|
+
record = opts[:record] || build_method_call(receiver, *args, &block)
|
71
84
|
@call_history << record
|
72
|
-
|
85
|
+
|
86
|
+
result = call_original(receiver, *args, &block)
|
87
|
+
record.result = result
|
73
88
|
end
|
74
89
|
|
75
90
|
def call_original(receiver, *args, &block)
|
data/lib/spy/instance.rb
CHANGED
data/lib/spy/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spy_rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josh Bodah
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-02-10 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Spy brings everything that's great about Sinon.JS to Ruby. Mocking frameworks
|
14
14
|
work by stubbing out functionality. Spy works by listening in on functionality and
|
@@ -53,7 +53,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
53
53
|
version: '0'
|
54
54
|
requirements: []
|
55
55
|
rubyforge_project:
|
56
|
-
rubygems_version: 2.
|
56
|
+
rubygems_version: 2.4.8
|
57
57
|
signing_key:
|
58
58
|
specification_version: 4
|
59
59
|
summary: SinonJS-style Test Spies for Ruby
|