bubot 0.0.4 → 0.0.5
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/lib/bubot.rb +6 -2
- data/lib/bubot/version.rb +1 -1
- data/spec/bubot_spec.rb +63 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2f70e8e24f5d875d8de41a2aa457fcbfeb374ee7
|
|
4
|
+
data.tar.gz: 34202112c92a9b3925f6e23db6b5f5dd05db2c22
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 522a9bbb8a21ac58ac88bb531780f08fca92cb5655d444125b522d2c97aa6cb98dc4221c768cde481cf21042fa3aaf698c400cbf42895a1c53d8e8b875d541d4
|
|
7
|
+
data.tar.gz: a51b03f8ecd290aa917717b70595ac7d260bd62b48f523485fad3f45c03753d7e77f1801346fd1c8803b3380c748ccf0c980fd36cb3db2d7d4755f1210035ffa
|
data/lib/bubot.rb
CHANGED
|
@@ -3,9 +3,13 @@ require "bubot/version"
|
|
|
3
3
|
module Bubot
|
|
4
4
|
|
|
5
5
|
def watch(method_name, timeout=0)
|
|
6
|
-
define_method("#{method_name}_with_feature") do
|
|
6
|
+
define_method("#{method_name}_with_feature") do |*args, &block|
|
|
7
7
|
start_time = Time.now
|
|
8
|
-
|
|
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
|
|
9
13
|
if (total_time = Time.now - start_time) > timeout
|
|
10
14
|
yield(self, total_time, method_return_value)
|
|
11
15
|
end
|
data/lib/bubot/version.rb
CHANGED
data/spec/bubot_spec.rb
CHANGED
|
@@ -158,5 +158,68 @@ describe Bubot do
|
|
|
158
158
|
bubot_observed.pass_return_value
|
|
159
159
|
end
|
|
160
160
|
end
|
|
161
|
+
|
|
162
|
+
describe "the original method" do
|
|
163
|
+
it "redefines the method to return the original value" do
|
|
164
|
+
class OriginalMethod
|
|
165
|
+
extend Bubot
|
|
166
|
+
|
|
167
|
+
watch :original do
|
|
168
|
+
#something
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
def original
|
|
172
|
+
"original value"
|
|
173
|
+
end
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
original_class = OriginalMethod.new
|
|
177
|
+
expect(original_class.original).to eql("original value")
|
|
178
|
+
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
it "accepts the original methods arguments" do
|
|
182
|
+
class OriginalArguments
|
|
183
|
+
extend Bubot
|
|
184
|
+
|
|
185
|
+
watch :arguments do
|
|
186
|
+
#something
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
def arguments(foo, bar)
|
|
190
|
+
# do something
|
|
191
|
+
end
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
original_class = OriginalArguments.new
|
|
195
|
+
expect(original_class).to receive(:arguments_without_feature).with("foo", "bar")
|
|
196
|
+
original_class.arguments('foo', 'bar')
|
|
197
|
+
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
it "accepts the original methods block" do
|
|
201
|
+
class OriginalBlock
|
|
202
|
+
extend Bubot
|
|
203
|
+
|
|
204
|
+
watch :with_block do
|
|
205
|
+
#something
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
def with_block
|
|
209
|
+
yield(true)
|
|
210
|
+
end
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
original_class = OriginalBlock.new
|
|
214
|
+
block_called = false
|
|
215
|
+
|
|
216
|
+
original_class.with_block do |value|
|
|
217
|
+
block_called = value
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
expect(block_called).to be_true
|
|
221
|
+
|
|
222
|
+
end
|
|
223
|
+
end
|
|
161
224
|
end
|
|
162
225
|
end
|