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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 64d02da3ec411aeb9266e4a61a295444c3cfcb39
4
- data.tar.gz: f03057fc9d0291fd1b50c2253a3b346e734a055a
3
+ metadata.gz: fb54969a1052380817f46a078bf3ebafe57acb2c
4
+ data.tar.gz: e29c5522dfd48423fe78b387fc06ce29e005d16d
5
5
  SHA512:
6
- metadata.gz: 1d8a048abf6d0856beb2887accce5d074eb81880e3ee5c3cf769631476eb956be7a85b7acd98c05e61f186b8c508008b57db9771cf69cea40a9f44fd6f1c39fc
7
- data.tar.gz: 2149e676609384f4adb744f0b5434a86c73c25ec6b2f742cb80b8a4c7b038a72e9e4ca86c0c77736d38faf6b37d3db338bed98eb220d830eb8c6f46922104884
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.all? {|f| f.call(receiver, *args)}
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
- call_original(receiver, *args, &block)
35
- else
36
- @before_callbacks.each {|f| f.call(receiver, *args)}
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
- if @around_procs.any?
39
- # Procify the original call
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
- # Keep wrapping the original proc with each around_proc
47
- @around_procs.reduce(original_proc) do |p, wrapper|
48
- Proc.new { wrapper.call receiver, *args, &p }
49
- end.call
50
- else
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
- @after_callbacks.each {|f| f.call(receiver, *args)}
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
- result
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 call_and_record(receiver, *args, &block)
63
- record = track_call(receiver, *args, &block)
64
- result = call_original(receiver, *args, &block)
65
- record.result = result
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 track_call(receiver, *args, &block)
69
- replayer = proc { call_original(receiver, *args, &block) }
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
- record
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
@@ -23,6 +23,10 @@ module Spy
23
23
  @strategy = Strategy.factory_build(self)
24
24
  end
25
25
 
26
+ def name
27
+ @original.name
28
+ end
29
+
26
30
  def call_count
27
31
  @call_history.size
28
32
  end
data/lib/spy/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Spy
2
- VERSION = '0.5.0'
2
+ VERSION = '1.0.0'
3
3
  end
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.5.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: 2015-07-20 00:00:00.000000000 Z
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.2.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