bubot 0.0.5 → 0.0.6

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: 2f70e8e24f5d875d8de41a2aa457fcbfeb374ee7
4
- data.tar.gz: 34202112c92a9b3925f6e23db6b5f5dd05db2c22
3
+ metadata.gz: 74f041f6e5452977767a4b2b312c88a9ccd1735b
4
+ data.tar.gz: de3f6d5b47ffae106723727bfd591f39b79bdf18
5
5
  SHA512:
6
- metadata.gz: 522a9bbb8a21ac58ac88bb531780f08fca92cb5655d444125b522d2c97aa6cb98dc4221c768cde481cf21042fa3aaf698c400cbf42895a1c53d8e8b875d541d4
7
- data.tar.gz: a51b03f8ecd290aa917717b70595ac7d260bd62b48f523485fad3f45c03753d7e77f1801346fd1c8803b3380c748ccf0c980fd36cb3db2d7d4755f1210035ffa
6
+ metadata.gz: 70539412f14584c7f9cdf7df404fa39204fc4eea735c995f4c94ac4d47caee338c8dfaa80eef6097e29868770a90e45026700be14f0279e03150219201379a4c
7
+ data.tar.gz: 1e6752083102f66d367290819c2142f171646fe14e301f3d2651d824d3248c1ee71525394590ae739e07c50627ec418b72974af043b43e93fbb613f48b072925
@@ -2,17 +2,22 @@ require "bubot/version"
2
2
 
3
3
  module Bubot
4
4
 
5
- def watch(method_name, timeout=0)
5
+ def watch(method_name, options={})
6
+ defaults = { timeout: 0 }
7
+ defaults.merge!(options)
6
8
  define_method("#{method_name}_with_feature") do |*args, &block|
7
9
  start_time = Time.now
8
- if block
9
- method_return_value = send("#{method_name}_without_feature".to_sym, *args, &block)
10
- else
11
- method_return_value = send("#{method_name}_without_feature".to_sym, *args)
12
- end
13
- if (total_time = Time.now - start_time) > timeout
14
- yield(self, total_time, method_return_value)
10
+
11
+ method_return_value = send("#{method_name}_without_feature".to_sym, *args, &block)
12
+
13
+ if (total_time = Time.now - start_time) > defaults[:timeout]
14
+ if options[:with]
15
+ options[:with].call(self, total_time, method_return_value)
16
+ else
17
+ yield(self, total_time, method_return_value)
18
+ end
15
19
  end
20
+
16
21
  method_return_value
17
22
  end
18
23
 
@@ -1,3 +1,3 @@
1
1
  module Bubot
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -14,11 +14,11 @@ class Qux
14
14
  include Foo
15
15
  extend Bubot
16
16
 
17
- watch :not_too_slow, 0.005 do
17
+ watch :not_too_slow, timeout: 0.005 do
18
18
  Baz.buz
19
19
  end
20
20
 
21
- watch :too_slow, 0.005 do
21
+ watch :too_slow, timeout: 0.005 do
22
22
  Baz.buz
23
23
  end
24
24
  end
@@ -40,7 +40,7 @@ describe Bubot do
40
40
  it "watch is before the method" do
41
41
  class Before
42
42
  extend Bubot
43
- watch(:next_method, 0.001) { Baz.buz }
43
+ watch(:next_method, timeout: 0.001) { Baz.buz }
44
44
  def next_method; sleep 0.002; end
45
45
  end
46
46
 
@@ -52,7 +52,7 @@ describe Bubot do
52
52
  class After
53
53
  extend Bubot
54
54
  def previous_method; sleep 0.002; end
55
- watch(:previous_method, 0.001) { Baz.buz }
55
+ watch(:previous_method, timeout: 0.001) { Baz.buz }
56
56
  end
57
57
 
58
58
  Baz.should_receive(:buz).once
@@ -78,7 +78,7 @@ describe Bubot do
78
78
  expect do
79
79
  class MethodDoesNotExist
80
80
  extend Bubot
81
- watch(:dont_exist, 0.001) { Baz.buz }
81
+ watch(:dont_exist, timeout: 0.001) { Baz.buz }
82
82
  end
83
83
  end.not_to raise_error
84
84
  end
@@ -94,7 +94,7 @@ describe Bubot do
94
94
 
95
95
  class PassesSelf
96
96
  extend Bubot
97
- watch(:pass_self, 0.001) do |instance|
97
+ watch(:pass_self, timeout: 0.001) do |instance|
98
98
  RecievesSelfStrategy.execute(instance)
99
99
  end
100
100
  def pass_self; sleep 0.002; end
@@ -115,7 +115,7 @@ describe Bubot do
115
115
 
116
116
  class PassesTime
117
117
  extend Bubot
118
- watch(:pass_time, 0.001) do |instance, time|
118
+ watch(:pass_time, timeout: 0.001) do |instance, time|
119
119
  RecievesTimeStrategy.execute(instance, time)
120
120
  end
121
121
  def pass_time; sleep 0.002; end
@@ -139,7 +139,7 @@ describe Bubot do
139
139
 
140
140
  class PassesReturnValue
141
141
  extend Bubot
142
- watch(:pass_return_value, 0.001) do |instance, time, return_value|
142
+ watch(:pass_return_value, timeout: 0.001) do |instance, time, return_value|
143
143
  RecievesReturnValueStrategy.execute(instance, time, return_value)
144
144
  end
145
145
  def pass_return_value
@@ -159,6 +159,35 @@ describe Bubot do
159
159
  end
160
160
  end
161
161
 
162
+ describe "using a `with` strategy" do
163
+
164
+ it ":with" do
165
+ class RespondingStrategy
166
+ def self.call(method_name, timeout, method_return_value)
167
+ # do something
168
+ end
169
+ end
170
+
171
+ class UsingWith
172
+ extend Bubot
173
+
174
+ watch :original, with: RespondingStrategy
175
+
176
+ def original
177
+ "original value"
178
+ end
179
+ end
180
+
181
+ original_class = UsingWith.new
182
+ expect(RespondingStrategy).to receive(:call) do |instance, time, value|
183
+ expect(instance).to be(original_class)
184
+ expect(time).to be > 0
185
+ expect(value).to eq "original value"
186
+ end
187
+ original_class.original
188
+ end
189
+ end
190
+
162
191
  describe "the original method" do
163
192
  it "redefines the method to return the original value" do
164
193
  class OriginalMethod
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bubot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Micah Cooper