waitfor 0.1.0 → 0.1.7
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.
- data/History.txt +30 -2
- data/Manifest.txt +10 -4
- data/README.rdoc +41 -24
- data/Rakefile +4 -4
- data/lib/waitfor.rb +26 -2
- data/lib/waitfor/fixnum.rb +29 -13
- data/lib/waitfor/settings/configuration.rb +35 -0
- data/lib/waitfor/settings/legacy_parser.rb +44 -0
- data/lib/waitfor/settings/parser.rb +59 -0
- data/lib/waitfor/timeout_error.rb +4 -0
- data/lib/waitfor/timer.rb +36 -27
- data/lib/waitfor/version.rb +6 -5
- data/spec/configuration_spec.rb +34 -0
- data/spec/fixnum_spec.rb +18 -20
- data/spec/legacy_parser_spec.rb +50 -0
- data/spec/parser_spec.rb +147 -0
- data/spec/spec.opts +3 -1
- data/spec/spec_helper.rb +9 -16
- data/spec/spec_helper_spec.rb +9 -19
- data/spec/timeout_error_spec.rb +10 -0
- data/spec/timer_spec.rb +90 -63
- data/spec/waitfor_spec.rb +44 -58
- metadata +36 -14
- data/lib/waitfor/waitfor_timeout_error.rb +0 -5
- data/spec/waitfor_timeout_error_spec.rb +0 -6
data/spec/waitfor_spec.rb
CHANGED
@@ -1,74 +1,60 @@
|
|
1
1
|
require File.dirname( __FILE__ ) + '/spec_helper.rb'
|
2
2
|
|
3
|
-
describe WaitFor
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
elapsed_time.should be < 1.second
|
3
|
+
describe WaitFor do
|
4
|
+
context "when event is true" do
|
5
|
+
it "should continue code execution without delay" do
|
6
|
+
Time.should_receive( :now ).once.and_return( NOW )
|
7
|
+
Kernel.should_not_receive( :sleep )
|
8
|
+
|
9
|
+
WaitFor.upto( :seconds => 1 ) { true }
|
10
|
+
end
|
12
11
|
end
|
13
|
-
end
|
14
12
|
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
context "when event is false" do
|
14
|
+
it "should halt code execution until timer expires then raise an error" do
|
15
|
+
Time.should_receive( :now ).exactly( 3 ).times.and_return( NOW, NOW + 1, NOW + 2 )
|
16
|
+
Kernel.should_receive( :sleep ).once
|
17
|
+
|
18
18
|
lambda {
|
19
|
-
WaitFor.upto
|
20
|
-
false
|
21
|
-
end
|
19
|
+
WaitFor.upto( :seconds => 2 ) { false }
|
22
20
|
}.should raise_error
|
23
|
-
|
24
|
-
|
25
|
-
elapsed_time.should be > 2
|
26
|
-
elapsed_time.should be < 4
|
21
|
+
end
|
27
22
|
end
|
28
|
-
end
|
29
23
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
false
|
35
|
-
end
|
36
|
-
}.should raise_error( CustomTestError )
|
37
|
-
end
|
38
|
-
end
|
24
|
+
context "when event is initially false but becomes true" do
|
25
|
+
before do
|
26
|
+
ToggleBetweenFalseAndTrue.reset_status
|
27
|
+
end
|
39
28
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
WaitFor.upto( :seconds => 0, :message => "Custom Error Message" ) do
|
44
|
-
false
|
45
|
-
end
|
46
|
-
}.should raise_error( "Custom Error Message" )
|
47
|
-
end
|
48
|
-
end
|
29
|
+
it "should halt code execution until event becomes true then continue" do
|
30
|
+
Time.should_receive( :now ).exactly( 2 ).times.and_return( NOW, NOW + 1 )
|
31
|
+
Kernel.should_receive( :sleep ).once
|
49
32
|
|
50
|
-
|
51
|
-
|
52
|
-
lambda {
|
53
|
-
WaitFor.upto( :seconds => 0, :exception => CustomTestError, :message => "Custom Error Message" ) do
|
54
|
-
false
|
55
|
-
end
|
56
|
-
}.should raise_error( CustomTestError, "Custom Error Message" )
|
33
|
+
WaitFor.upto( :seconds => 2 ) { ToggleBetweenFalseAndTrue.status? }
|
34
|
+
end
|
57
35
|
end
|
58
|
-
end
|
59
36
|
|
60
|
-
|
61
|
-
|
62
|
-
|
37
|
+
context "when event is false and has custom exception" do
|
38
|
+
it "should raise a CustomTestError error" do
|
39
|
+
lambda {
|
40
|
+
WaitFor.upto( :seconds => 0, :exception => CustomTestError ) { false }
|
41
|
+
}.should raise_error( CustomTestError )
|
42
|
+
end
|
43
|
+
end
|
63
44
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
45
|
+
context "when event is false and has custom message" do
|
46
|
+
it "should raise an error with a custom message" do
|
47
|
+
lambda {
|
48
|
+
WaitFor.upto( :seconds => 0, :message => "Custom Error Message" ) { false }
|
49
|
+
}.should raise_error( "Custom Error Message" )
|
50
|
+
end
|
51
|
+
end
|
69
52
|
|
70
|
-
|
71
|
-
|
53
|
+
context "when event is false and has custom exception with a custom message" do
|
54
|
+
it "should raise a CustomTestError error with a custom message" do
|
55
|
+
lambda {
|
56
|
+
WaitFor.upto( :seconds => 0, :exception => CustomTestError, :message => "Custom Error Message" ) { false }
|
57
|
+
}.should raise_error( CustomTestError, "Custom Error Message" )
|
58
|
+
end
|
72
59
|
end
|
73
60
|
end
|
74
|
-
|
metadata
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: waitfor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 21
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 7
|
10
|
+
version: 0.1.7
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- James Bobowski
|
@@ -9,20 +15,25 @@ autorequire:
|
|
9
15
|
bindir: bin
|
10
16
|
cert_chain: []
|
11
17
|
|
12
|
-
date:
|
13
|
-
default_executable:
|
18
|
+
date: 2011-04-19 00:00:00 Z
|
14
19
|
dependencies:
|
15
20
|
- !ruby/object:Gem::Dependency
|
16
21
|
name: hoe
|
17
|
-
|
18
|
-
|
19
|
-
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
20
25
|
requirements:
|
21
26
|
- - ">="
|
22
27
|
- !ruby/object:Gem::Version
|
28
|
+
hash: 5
|
29
|
+
segments:
|
30
|
+
- 2
|
31
|
+
- 3
|
32
|
+
- 3
|
23
33
|
version: 2.3.3
|
24
|
-
|
25
|
-
|
34
|
+
type: :development
|
35
|
+
version_requirements: *id001
|
36
|
+
description: Simple solution to the sleep( ) test anti-pattern. Blocks execution until a supplied block returns true, or a specified time interval is reached, at which point an error is raised.
|
26
37
|
email:
|
27
38
|
- james.bobowski@gmail.com
|
28
39
|
executables: []
|
@@ -39,17 +50,22 @@ files:
|
|
39
50
|
- README.rdoc
|
40
51
|
- lib/waitfor.rb
|
41
52
|
- lib/waitfor/fixnum.rb
|
53
|
+
- lib/waitfor/timeout_error.rb
|
42
54
|
- lib/waitfor/timer.rb
|
43
55
|
- lib/waitfor/version.rb
|
44
|
-
- lib/waitfor/
|
56
|
+
- lib/waitfor/settings/configuration.rb
|
57
|
+
- lib/waitfor/settings/legacy_parser.rb
|
58
|
+
- lib/waitfor/settings/parser.rb
|
59
|
+
- spec/configuration_spec.rb
|
45
60
|
- spec/fixnum_spec.rb
|
61
|
+
- spec/legacy_parser_spec.rb
|
62
|
+
- spec/parser_spec.rb
|
46
63
|
- spec/spec.opts
|
47
64
|
- spec/spec_helper.rb
|
48
65
|
- spec/spec_helper_spec.rb
|
66
|
+
- spec/timeout_error_spec.rb
|
49
67
|
- spec/timer_spec.rb
|
50
68
|
- spec/waitfor_spec.rb
|
51
|
-
- spec/waitfor_timeout_error_spec.rb
|
52
|
-
has_rdoc: true
|
53
69
|
homepage: http://github.com/jamesbobowski/waitfor
|
54
70
|
licenses: []
|
55
71
|
|
@@ -60,21 +76,27 @@ rdoc_options:
|
|
60
76
|
require_paths:
|
61
77
|
- lib
|
62
78
|
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
63
80
|
requirements:
|
64
81
|
- - ">="
|
65
82
|
- !ruby/object:Gem::Version
|
83
|
+
hash: 3
|
84
|
+
segments:
|
85
|
+
- 0
|
66
86
|
version: "0"
|
67
|
-
version:
|
68
87
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
69
89
|
requirements:
|
70
90
|
- - ">="
|
71
91
|
- !ruby/object:Gem::Version
|
92
|
+
hash: 3
|
93
|
+
segments:
|
94
|
+
- 0
|
72
95
|
version: "0"
|
73
|
-
version:
|
74
96
|
requirements: []
|
75
97
|
|
76
98
|
rubyforge_project: waitfor
|
77
|
-
rubygems_version: 1.
|
99
|
+
rubygems_version: 1.8.7
|
78
100
|
signing_key:
|
79
101
|
specification_version: 3
|
80
102
|
summary: Generic 'wait for' method
|