with_retries 0.0.2 → 0.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a246d623e3529e5e633805268c6c2677f78a3791
4
- data.tar.gz: 59f954301fa56ee90c1f30b5879fa4a44c377c93
3
+ metadata.gz: d61893c812a1f6e1112e410fb331ce9ad6d57688
4
+ data.tar.gz: 49cf230b666ad388904127b6ab8dcca80805a28e
5
5
  SHA512:
6
- metadata.gz: 33d7e074f2f5e025db49f12b58b3a7410b63acfdf3cd60f0d2d367a94577323a93ab65d38c3ff5d7312ccf412457cf6b41bb3cc4f8e6ba7dd8983730030d0923
7
- data.tar.gz: bba2dba316f56ceee9673150a9e7c6d4f5bc8bcff00fe51f32629d634d1b9231954aae6ba95bcf736fed639ab10f63136e2ba103149f78cd9a14581a0b0b8f67
6
+ metadata.gz: 992fb1884a60a8ad7be7a84de3a644af93a20f9fd1c5a3beab24ad430995c8756f800c503d48d0b7144298de689f22942748f22b2329361e53baf02cc7af1b39
7
+ data.tar.gz: d01a7a028a0d209c8bd6fa871a08125374969889c2f73753ac33d4efbdb4f5f1421cf521f87109776222ceece88a7919c194e7a816fa1b12621d42724abac7c2
@@ -1,3 +1,3 @@
1
1
  module WithRetries
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/with_retries.rb CHANGED
@@ -5,12 +5,15 @@ module Kernel
5
5
  attempts = params[:attempts] or
6
6
  raise ArgumentError.new("Attempts parameter not provided")
7
7
  logger = params[:logger]
8
+ timeout = params[:timeout]
8
9
 
9
10
  begin
10
11
  yield
11
12
  rescue *errors => e
12
13
  attempts -= 1
13
14
 
15
+ Kernel.sleep(timeout) if timeout
16
+
14
17
  if logger
15
18
  times = (attempts == 1 ? "time" : "times")
16
19
 
@@ -25,4 +28,3 @@ module Kernel
25
28
  end
26
29
  end
27
30
  end
28
-
@@ -52,6 +52,34 @@ describe Kernel do
52
52
  end.to raise_error
53
53
  end
54
54
  end
55
+
56
+ context "when given a timeout parameter" do
57
+ it "retries the block after sleeping for the provided timeout" do
58
+ Kernel.should_receive(:sleep).with(5).twice
59
+
60
+ expect do
61
+ with_retries(Boom, attempts: 2, timeout: 5) do
62
+ 3.times do
63
+ raise Boom.new
64
+ end
65
+ end
66
+ end.to raise_error(Boom)
67
+ end
68
+ end
69
+
70
+ context "when not given a timeout parameter" do
71
+ it "does not sleep" do
72
+ Kernel.should_not_receive(:sleep)
73
+
74
+ expect do
75
+ with_retries(Boom, attempts: 2) do
76
+ 3.times do
77
+ raise Boom.new
78
+ end
79
+ end
80
+ end.to raise_error(Boom)
81
+ end
82
+ end
55
83
  end
56
84
 
57
85
  context "when not given an attempts parameter" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: with_retries
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryan Woods
@@ -10,20 +10,20 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-10-15 00:00:00.000000000 Z
13
+ date: 2014-05-07 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  requirements:
19
- - - ~>
19
+ - - "~>"
20
20
  - !ruby/object:Gem::Version
21
21
  version: 2.14.1
22
22
  type: :development
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
- - - ~>
26
+ - - "~>"
27
27
  - !ruby/object:Gem::Version
28
28
  version: 2.14.1
29
29
  description: Adds a with_retries method to Kernel for retrying things
@@ -33,7 +33,7 @@ executables: []
33
33
  extensions: []
34
34
  extra_rdoc_files: []
35
35
  files:
36
- - .gitignore
36
+ - ".gitignore"
37
37
  - Gemfile
38
38
  - Guardfile
39
39
  - LICENSE.txt
@@ -53,17 +53,17 @@ require_paths:
53
53
  - lib
54
54
  required_ruby_version: !ruby/object:Gem::Requirement
55
55
  requirements:
56
- - - '>='
56
+ - - ">="
57
57
  - !ruby/object:Gem::Version
58
58
  version: '0'
59
59
  required_rubygems_version: !ruby/object:Gem::Requirement
60
60
  requirements:
61
- - - '>='
61
+ - - ">="
62
62
  - !ruby/object:Gem::Version
63
63
  version: '0'
64
64
  requirements: []
65
65
  rubyforge_project:
66
- rubygems_version: 2.0.3
66
+ rubygems_version: 2.2.2
67
67
  signing_key:
68
68
  specification_version: 4
69
69
  summary: Maybe later