goran 0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/spec/goran_spec.rb +30 -0
- data/spec/spec_helper.rb +13 -0
- metadata +57 -0
data/spec/goran_spec.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
describe Goran do
|
2
|
+
it 'serves for a maximum of x tries' do
|
3
|
+
count = 0
|
4
|
+
Goran.serve(max_tries: 3, retry_if: lambda {|x| [1,2,3].include? x}) { count += 1 }.should == 3
|
5
|
+
end
|
6
|
+
|
7
|
+
it 'stops trying if the block runs successfully' do
|
8
|
+
count = 0
|
9
|
+
Goran.serve(max_tries: 3, retry_if: 0) { count+=1 }.should == 1
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'uses fallback value if one is provided and none of the tries are successful' do
|
13
|
+
count = 0
|
14
|
+
Goran.serve(max_tries: 3, retry_if: nil, fallback: 'hello') { nil }.should == 'hello'
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'protects from exceptions' do
|
18
|
+
expect { Goran.serve(max_tries: 3, retry_if: 0, rescue_from: StandardError) { raise StandardError, 'Boo' } }.to_not raise_error
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'does not protect from exception on the last run if so desired' do
|
22
|
+
expect { Goran.serve(max_tries: 3, retry_if: 0, rescue_from: [StandardError, ArgumentError], rescue_last: false) { raise StandardError, 'Boo' } }.to raise_error
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'runs a proc on rescue if one is provided' do
|
26
|
+
count = 0
|
27
|
+
Goran.serve(max_tries: 3, retry_if: 0, rescue_from: StandardError, on_rescue: lambda {|e| count+=1 }) { raise StandardError, 'Boo' }
|
28
|
+
count.should == 3
|
29
|
+
end
|
30
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper.rb"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
9
|
+
config.run_all_when_everything_filtered = true
|
10
|
+
config.filter_run :focus
|
11
|
+
end
|
12
|
+
|
13
|
+
require File.dirname(__FILE__)+'/../lib/goran'
|
metadata
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: goran
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.5'
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Nitesh
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-04-30 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: ! " Named after Goran Invanisevic, the tennis legend who won the Wimbledon
|
15
|
+
after losing the final 3 times, \n Goran provides a simple syntax to run a block
|
16
|
+
of code multiple times. E.g.\n \n * run block 'x' number of times\n * run
|
17
|
+
until the block returns a non-nil value\n * run until the block does not raise
|
18
|
+
an exception\n * run until the block returns a non-zero value, to a maximum of
|
19
|
+
3 times, and return nil if all runs return a 0\n \n Goran is especially useful
|
20
|
+
for running network calls which have unexpected outputs like 404, timeouts. It is
|
21
|
+
an\n easy way to build in retry logic into these calls and handle cases where
|
22
|
+
these calls do not succeed at all.\n"
|
23
|
+
email:
|
24
|
+
- nitesh@wallwisher.com
|
25
|
+
executables: []
|
26
|
+
extensions: []
|
27
|
+
extra_rdoc_files: []
|
28
|
+
files:
|
29
|
+
- spec/goran_spec.rb
|
30
|
+
- spec/spec_helper.rb
|
31
|
+
homepage: http://github.com/wallwisher/goran
|
32
|
+
licenses: []
|
33
|
+
post_install_message:
|
34
|
+
rdoc_options: []
|
35
|
+
require_paths:
|
36
|
+
- lib
|
37
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ! '>='
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
45
|
+
requirements:
|
46
|
+
- - ! '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
requirements: []
|
50
|
+
rubyforge_project:
|
51
|
+
rubygems_version: 1.8.23
|
52
|
+
signing_key:
|
53
|
+
specification_version: 3
|
54
|
+
summary: Goran is a ruby library to run blocks of code that return unexpected values/raise
|
55
|
+
Exceptions multiple times or until they succeed
|
56
|
+
test_files: []
|
57
|
+
has_rdoc:
|