attempt_to 0.3 → 0.4

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9cee4b7546988224234bf6ce6290c5af576b1db1
4
+ data.tar.gz: 1ec8e3c7ec2105db8e2326e7131bd3c6b34dc233
5
+ SHA512:
6
+ metadata.gz: 02eb2d298df2af64bc20b0dc00fbd603c89c6eb0e20db89d4140f29a42b2fb2406bb465a1f8d4cd2718c58880af6a4be98144e2d4f0511c1c25eefb35bc2c145
7
+ data.tar.gz: 8f5baa089c594cdb1ac94aa004563b0a7992adcb33e56e7682067682bad4f83f3e0bf067792ba11263159ff28a79fea9b8295abd233c8d3d5dad46cf4cd23946
@@ -14,8 +14,24 @@ module AttemptTo
14
14
  end
15
15
  }
16
16
  end
17
+
18
+ def self.attempt_to_with_timeout(seconds)
19
+ Timeout::timeout(seconds) {
20
+ success = false
21
+ while not success
22
+ begin
23
+ success = yield
24
+ rescue Exception
25
+ end
26
+ end
27
+ }
28
+ end
17
29
  end
18
30
 
19
31
  def attempt_to(something, amount, &code_block)
20
32
  AttemptTo.attempt_to(something, amount, &code_block)
21
- end
33
+ end
34
+
35
+ def attempt_to_with_timeout(seconds, &code_block)
36
+ AttemptTo.attempt_to_with_timeout(seconds, &code_block)
37
+ end
@@ -1,4 +1,4 @@
1
1
 
2
2
  module AttemptTo
3
- VERSION = "0.3"
3
+ VERSION = "0.4"
4
4
  end
@@ -20,7 +20,7 @@ describe "Attempt to do something a couple of times, if it fails, bail out." do
20
20
  "returns"
21
21
  }.should == "returns"
22
22
  end
23
-
23
+
24
24
  it "calls the block multiple times when it fails " do
25
25
  Kernel.should_receive(:puts).with("Failed attempt #1 to do something. Error message: wrong 1")
26
26
  attempt_to("do something", 3) {
@@ -29,7 +29,7 @@ describe "Attempt to do something a couple of times, if it fails, bail out." do
29
29
  }
30
30
  @attempts.should == 2
31
31
  end
32
-
32
+
33
33
  it "bails out aften the maximum amount of attempts" do
34
34
  Kernel.should_receive(:puts).exactly(3).times
35
35
  Kernel.should_receive(:puts).with("Attempted 3 times to do this. Giving up...")
@@ -39,15 +39,28 @@ describe "Attempt to do something a couple of times, if it fails, bail out." do
39
39
  raise(Exception, "wrong!")
40
40
  }
41
41
  }.should raise_error(SystemExit)
42
-
42
+
43
43
  @attempts.should == 3
44
44
  end
45
-
45
+
46
46
  # it "Can run the example code" do
47
47
  # attempt_to('connect to the network', 3) {
48
48
  # TCPSocket.new("some.very.weird.domain.name", 9342)
49
49
  # }
50
- #
50
+ #
51
51
  # end
52
-
52
+ #
53
+ it "can do an attempt_to with a timeout" do
54
+ attempt_to_with_timeout(1) {
55
+ @attempts += 1
56
+ raise(Exception, "wrong #{@attempts}") if @attempts < 5
57
+ @attempts > 10
58
+ }
59
+ @attempts.should == 11
60
+ end
61
+
62
+ it "will return a Timeout when the condition never happens" do
63
+ expect { attempt_to_with_timeout(0.3) { false } }.to raise_error(Timeout::Error, "execution expired")
64
+ end
65
+
53
66
  end
metadata CHANGED
@@ -1,49 +1,50 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: attempt_to
3
- version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: "0.3"
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.4'
6
5
  platform: ruby
7
- authors:
6
+ authors:
8
7
  - Bas Vodde
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
-
13
- date: 2012-12-03 00:00:00 +08:00
14
- default_executable:
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
11
+ date: 2014-07-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
17
14
  name: rake
18
- prerelease: false
19
- requirement: &id001 !ruby/object:Gem::Requirement
20
- none: false
21
- requirements:
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
22
17
  - - ">="
23
- - !ruby/object:Gem::Version
24
- version: "0"
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
25
20
  type: :runtime
26
- version_requirements: *id001
27
- - !ruby/object:Gem::Dependency
28
- name: rspec
29
21
  prerelease: false
30
- requirement: &id002 !ruby/object:Gem::Requirement
31
- none: false
32
- requirements:
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
33
31
  - - ">="
34
- - !ruby/object:Gem::Version
32
+ - !ruby/object:Gem::Version
35
33
  version: 2.0.0
36
34
  type: :development
37
- version_requirements: *id002
38
- description: AttemptTo calls a code block and re-tries it if it throws an exception. Otherwise exits
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 2.0.0
41
+ description: AttemptTo calls a code block and re-tries it if it throws an exception.
42
+ Otherwise exits
39
43
  email: basv@odd-e.com
40
44
  executables: []
41
-
42
45
  extensions: []
43
-
44
46
  extra_rdoc_files: []
45
-
46
- files:
47
+ files:
47
48
  - Gemfile
48
49
  - README.md
49
50
  - Rakefile
@@ -52,33 +53,27 @@ files:
52
53
  - lib/attempt_to/attempt_to.rb
53
54
  - lib/attempt_to/version.rb
54
55
  - spec/attempt_to_spec.rb
55
- has_rdoc: true
56
56
  homepage: https://github.com/basvodde/attempt_to
57
57
  licenses: []
58
-
58
+ metadata: {}
59
59
  post_install_message:
60
60
  rdoc_options: []
61
-
62
- require_paths:
61
+ require_paths:
63
62
  - lib
64
- required_ruby_version: !ruby/object:Gem::Requirement
65
- none: false
66
- requirements:
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
67
65
  - - ">="
68
- - !ruby/object:Gem::Version
69
- version: "0"
70
- required_rubygems_version: !ruby/object:Gem::Requirement
71
- none: false
72
- requirements:
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
73
70
  - - ">="
74
- - !ruby/object:Gem::Version
75
- version: "0"
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
76
73
  requirements: []
77
-
78
74
  rubyforge_project:
79
- rubygems_version: 1.6.2
75
+ rubygems_version: 2.2.2
80
76
  signing_key:
81
- specification_version: 3
77
+ specification_version: 4
82
78
  summary: AttemptTo is a small utility for attempting a code block multiple times
83
79
  test_files: []
84
-