anticipate 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +24 -0
- data/lib/anticipate.rb +1 -1
- data/lib/anticipate/anticipator.rb +1 -1
- data/spec/anticipate/anticipator_spec.rb +14 -1
- metadata +4 -4
data/README.rdoc
CHANGED
@@ -20,4 +20,28 @@ Blocks should contain an assertion, i.e. raise a descriptive error if some condi
|
|
20
20
|
|
21
21
|
The first try is attempted immediately, there is no sleep before the first yield.
|
22
22
|
|
23
|
+
== Defining your own timings
|
24
|
+
|
25
|
+
If lots of your code needs to wait for things to happen, you might consider defining your own timing module, e.g:
|
26
|
+
|
27
|
+
module Timing
|
28
|
+
include Anticipate
|
29
|
+
|
30
|
+
def very_soon
|
31
|
+
sleeping(0.1).seconds.between_tries.failing_after(10).tries do
|
32
|
+
yield
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def eventually
|
37
|
+
sleeping(2).seconds.between_tries.failing_after(5).tries do
|
38
|
+
yield
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
...that way you can adjust timing details in one place as the system grows.
|
44
|
+
|
45
|
+
== Alternatives
|
46
|
+
|
23
47
|
I'm aware of a couple of gems performing the begin-rescue-sleep-retry dance, namely 'retry' and 'attempt'. The aim of this library is to offer more expressive syntax.
|
data/lib/anticipate.rb
CHANGED
@@ -10,7 +10,7 @@ module Anticipate
|
|
10
10
|
|
11
11
|
describe "#anticipate" do
|
12
12
|
|
13
|
-
describe "when the block eventually stops raising" do
|
13
|
+
describe "when the block eventually stops raising a StandardError" do
|
14
14
|
it "sleeps the given interval between tries" do
|
15
15
|
@sleeper.should_receive(:sleep).with(1).exactly(8).times
|
16
16
|
tries = 0
|
@@ -29,6 +29,19 @@ module Anticipate
|
|
29
29
|
}.should_not raise_error
|
30
30
|
end
|
31
31
|
end
|
32
|
+
|
33
|
+
describe "when the block eventually stops raising an Exception (that is not a StandardError)" do
|
34
|
+
|
35
|
+
it "sleeps the given interval between tries" do
|
36
|
+
@sleeper.should_receive(:sleep).with(1).exactly(8).times
|
37
|
+
tries = 0
|
38
|
+
@anticipator.anticipate(1,9) do
|
39
|
+
raise Exception.new unless (tries += 1) == 9
|
40
|
+
end
|
41
|
+
tries.should == 9
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
32
45
|
|
33
46
|
describe "when the block always raises" do
|
34
47
|
describe "when waiting for one second" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: anticipate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-05-24 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Fluent interface for try-rescue-sleep-retry-abort
|
15
15
|
email: joshuachisholm@gmail.com
|
@@ -48,8 +48,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
48
48
|
version: '0'
|
49
49
|
requirements: []
|
50
50
|
rubyforge_project:
|
51
|
-
rubygems_version: 1.8.
|
51
|
+
rubygems_version: 1.8.24
|
52
52
|
signing_key:
|
53
53
|
specification_version: 3
|
54
|
-
summary: anticipate-0.0
|
54
|
+
summary: anticipate-0.1.0
|
55
55
|
test_files: []
|