just-retry 0.1.3 → 0.2.0

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: 6923f70aaf3debcee318fed8a0fef4673ae364c9
4
- data.tar.gz: f4c7c2ebca157bc784c631723d76625012a66e27
3
+ metadata.gz: 5c22743aab9c834710d3217c306cb0088e2dc9ce
4
+ data.tar.gz: 2163b00419075b3ea14889f3e1334fb5a7b44c0c
5
5
  SHA512:
6
- metadata.gz: bf4854695de57e5abc3361fe0fcf2cbb130e298bb353295ea36dc6750f480badb36f38419440a9d618b874817e652ca807c86cc151bf95467f654220105933c9
7
- data.tar.gz: 35fb20b6467ba1a8d6d4db2bae805c1c691fce590294ba012ec55f27cc0b157fad51edce48ec738bcbbe6946fdba9acceacf6ae08a8a1b193b19741ad4205d19
6
+ metadata.gz: 4318cdc6e3797bef27e28c6a6bcd98f7b30a99169fb06f0f15c4eaf1af8eaced9c05c81300e519cca236fea4b2a78c828d9703bdb42fb722c89bb6459ec42824
7
+ data.tar.gz: 13192123e8fb586bdfacb959d73d43753e3248781fb59c27fefdf865380bab4e071224e02190a7ab64b5ed04fcecdd50a7855c57e4a07d6380ea19f9b9c25941
data/README.md CHANGED
@@ -30,7 +30,7 @@ Just::retry do
30
30
  end
31
31
  ```
32
32
 
33
- You can limit which exceptions are rescued.
33
+ You can specify which exception is rescued.
34
34
 
35
35
  ```ruby
36
36
  Just::retry on: exception do
data/just-retry.gemspec CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
8
8
  spec.version = Just::Retry::VERSION
9
9
  spec.authors = ["Michael Greenly"]
10
10
  spec.email = ["mgreenly@gmail.com"]
11
- spec.description = %q{Provides a counted retry machanism}
12
11
  spec.summary = %q{Provides a counted retry mechansim}
12
+ spec.description = spec.summary
13
13
  spec.homepage = "https://github.com/mgreenly/just-retry"
14
14
  spec.license = "MIT"
15
15
 
@@ -20,4 +20,5 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.3"
22
22
  spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
23
24
  end
@@ -1,5 +1,5 @@
1
1
  module Just
2
2
  module Retry
3
- VERSION = "0.1.3"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
data/lib/just/retry.rb CHANGED
@@ -2,12 +2,12 @@ require "just/retry/version"
2
2
 
3
3
  module Just
4
4
  def retry(opts={})
5
- opts = { :delay => 0.0, :tries => 2, :exception => Exception }.merge(opts)
6
- delay, tries, exception, logger = opts[:delay], opts[:tries], opts[:exception], opts[:logger]
5
+ opts = {delay: 0.0, on: StandardError, tries: 2}.merge(opts)
6
+ delay, tries, exception, logger = opts[:delay], opts[:tries], opts[:on], opts[:logger]
7
7
  count = 0
8
8
  begin
9
9
  count += 1
10
- return yield
10
+ yield
11
11
  rescue exception => e
12
12
  if count < tries
13
13
  if logger
@@ -19,7 +19,7 @@ module Just
19
19
  end
20
20
  retry
21
21
  else
22
- raise
22
+ raise e
23
23
  end
24
24
  end
25
25
  end
@@ -0,0 +1,70 @@
1
+ require 'just/retry'
2
+
3
+ describe "Just::retry" do
4
+
5
+ it "The block is only called once if it succeeds" do
6
+ object = Object.new
7
+ object.should_receive(:ping).once.and_return(:success)
8
+ expect {
9
+ Just::retry do
10
+ object.ping
11
+ end
12
+ }.not_to raise_error(Exception)
13
+ end
14
+
15
+ it "The block is called twice by default if it fails" do
16
+ object = Object.new
17
+ object.should_receive(:ping).twice { raise StandardError }
18
+ expect {
19
+ Just::retry do
20
+ object.ping
21
+ end
22
+ }.to raise_error(StandardError)
23
+ end
24
+
25
+ it "The block is called n times when a try count is specified" do
26
+ object = Object.new
27
+ n = 5
28
+ object.should_receive(:ping).exactly(n).times { raise StandardError }
29
+ expect {
30
+ Just::retry tries: n do
31
+ object.ping
32
+ end
33
+ }.to raise_error(StandardError)
34
+ end
35
+
36
+ it "Unexpected exceptions are reraised" do
37
+ object = Object.new
38
+ object.should_receive(:ping).once { raise StandardError }
39
+ expect {
40
+ Just::retry on: IOError do
41
+ object.ping
42
+ end
43
+ }.to raise_error(StandardError)
44
+ end
45
+
46
+ it "sleep is called if it's provided" do
47
+ object = Object.new
48
+ object.should_receive(:ping).twice { raise StandardError }
49
+ Just.stub!(:sleep)
50
+ Just.should_receive(:sleep).once.with(30)
51
+ expect {
52
+ Just::retry delay: 30 do
53
+ object.ping
54
+ end
55
+ }.to raise_error(StandardError)
56
+ end
57
+
58
+ it "the retry is logged if a log is provided" do
59
+ object = Object.new
60
+ object.should_receive(:ping).twice { raise StandardError }
61
+ logger = Object.new
62
+ logger.should_receive(:error).with(any_args)
63
+ logger.should_receive(:debug).with(any_args)
64
+ expect {
65
+ Just::retry logger: logger do
66
+ object.ping
67
+ end
68
+ }.to raise_error(StandardError)
69
+ end
70
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: just-retry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Greenly
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-01 00:00:00.000000000 Z
11
+ date: 2013-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,7 +38,21 @@ dependencies:
38
38
  - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- description: Provides a counted retry machanism
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Provides a counted retry mechansim
42
56
  email:
43
57
  - mgreenly@gmail.com
44
58
  executables: []
@@ -53,6 +67,7 @@ files:
53
67
  - just-retry.gemspec
54
68
  - lib/just/retry.rb
55
69
  - lib/just/retry/version.rb
70
+ - spec/retry_spec.rb
56
71
  homepage: https://github.com/mgreenly/just-retry
57
72
  licenses:
58
73
  - MIT
@@ -77,4 +92,5 @@ rubygems_version: 2.0.3
77
92
  signing_key:
78
93
  specification_version: 4
79
94
  summary: Provides a counted retry mechansim
80
- test_files: []
95
+ test_files:
96
+ - spec/retry_spec.rb