wait_until 0.0.1 → 0.1.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.
- data/lib/wait_until/version.rb +1 -1
- data/lib/wait_until/wait.rb +8 -7
- data/spec/lib/wait_until/wait_spec.rb +93 -21
- data/spec/spec_helper.rb +1 -4
- metadata +30 -14
data/lib/wait_until/version.rb
CHANGED
data/lib/wait_until/wait.rb
CHANGED
@@ -5,17 +5,18 @@ module WaitUntil
|
|
5
5
|
|
6
6
|
attr_accessor :default_timeout_in_seconds
|
7
7
|
|
8
|
-
def until_true!(description, &block)
|
8
|
+
def until_true!(description, options={}, &block)
|
9
|
+
timeout_in_seconds = options[:timeout_in_seconds] || self.default_timeout_in_seconds
|
9
10
|
start_time = Time.now
|
10
11
|
last_exc = nil
|
11
|
-
|
12
|
+
loop do
|
12
13
|
begin
|
13
14
|
return if block.call
|
14
15
|
rescue => exc
|
15
16
|
last_exc = exc
|
16
17
|
end
|
17
18
|
elapsed_time = Time.now - start_time
|
18
|
-
if elapsed_time >=
|
19
|
+
if elapsed_time >= timeout_in_seconds
|
19
20
|
failure_message = "Timed-out waiting until '#{description}'"
|
20
21
|
failure_message << ". Last observed exception: #{last_exc}" if last_exc
|
21
22
|
raise failure_message
|
@@ -23,12 +24,12 @@ module WaitUntil
|
|
23
24
|
end
|
24
25
|
end
|
25
26
|
|
26
|
-
def until_false!(description, &block)
|
27
|
-
until_true!(description) { !block.call }
|
27
|
+
def until_false!(description, options={}, &block)
|
28
|
+
until_true!(description, options) { !block.call }
|
28
29
|
end
|
29
30
|
|
30
|
-
def until!(description, &block)
|
31
|
-
until_true!(description) do
|
31
|
+
def until!(description, options={}, &block)
|
32
|
+
until_true!(description, options) do
|
32
33
|
block.call
|
33
34
|
true
|
34
35
|
end
|
@@ -9,25 +9,49 @@ describe WaitUntil::Wait do
|
|
9
9
|
|
10
10
|
describe ".until_true!" do
|
11
11
|
|
12
|
-
|
12
|
+
context "when the block returns true" do
|
13
|
+
|
14
|
+
let(:block) do
|
15
|
+
lambda { WaitUntil::Wait.until_true!("some operation") { true } }
|
16
|
+
end
|
13
17
|
|
14
18
|
it "should execute without error" do
|
15
|
-
|
19
|
+
block.should_not raise_error
|
16
20
|
end
|
17
21
|
|
18
22
|
end
|
19
23
|
|
20
|
-
|
24
|
+
context "when the blocks always returns false" do
|
21
25
|
|
22
|
-
|
26
|
+
let(:timeout_in_seconds) { nil }
|
27
|
+
let(:block) do
|
23
28
|
lambda do
|
24
|
-
WaitUntil::Wait.until_true!("another operation finishes") { false }
|
25
|
-
end
|
29
|
+
WaitUntil::Wait.until_true!("another operation finishes", timeout_in_seconds: timeout_in_seconds) { false }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should raise an error indicating the operation timed-out" do
|
34
|
+
block.should raise_error(/Timed-out waiting until 'another operation finishes'/i)
|
35
|
+
end
|
36
|
+
|
37
|
+
context "and a timeout is provided" do
|
38
|
+
|
39
|
+
let(:timeout_in_seconds) { 2 }
|
40
|
+
|
41
|
+
it "should wait until at least a period of time matching the timeout before raising an error" do
|
42
|
+
start_time = Time.now
|
43
|
+
|
44
|
+
block.should raise_error
|
45
|
+
|
46
|
+
period_of_time_waited = (Time.now - start_time)
|
47
|
+
period_of_time_waited.should be >= timeout_in_seconds
|
48
|
+
end
|
49
|
+
|
26
50
|
end
|
27
51
|
|
28
52
|
end
|
29
53
|
|
30
|
-
|
54
|
+
context "when the block eventually returns true" do
|
31
55
|
|
32
56
|
it "should execute without error" do
|
33
57
|
invocation_count = 0
|
@@ -45,25 +69,49 @@ describe WaitUntil::Wait do
|
|
45
69
|
|
46
70
|
describe ".until_false!" do
|
47
71
|
|
48
|
-
|
72
|
+
context "when the block returns false" do
|
73
|
+
|
74
|
+
let(:block) do
|
75
|
+
lambda { WaitUntil::Wait.until_false!("some operation") { false } }
|
76
|
+
end
|
49
77
|
|
50
78
|
it "should execute without error" do
|
51
|
-
|
79
|
+
block.should_not raise_error
|
52
80
|
end
|
53
81
|
|
54
82
|
end
|
55
83
|
|
56
|
-
|
84
|
+
context "when the blocks always returns true" do
|
57
85
|
|
58
|
-
|
86
|
+
let(:timeout_in_seconds) { nil }
|
87
|
+
let(:block) do
|
59
88
|
lambda do
|
60
|
-
WaitUntil::Wait.until_false!("another operation finishes") { true }
|
61
|
-
end
|
89
|
+
WaitUntil::Wait.until_false!("another operation finishes", timeout_in_seconds: timeout_in_seconds) { true }
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should raise an error indicating the operation timed-out" do
|
94
|
+
block.should raise_error(/Timed-out waiting until 'another operation finishes'/i)
|
95
|
+
end
|
96
|
+
|
97
|
+
context "and a timeout is provided" do
|
98
|
+
|
99
|
+
let(:timeout_in_seconds) { 2 }
|
100
|
+
|
101
|
+
it "should wait until at least a period of time matching the timeout before raising an error" do
|
102
|
+
start_time = Time.now
|
103
|
+
|
104
|
+
block.should raise_error
|
105
|
+
|
106
|
+
period_of_time_waited = (Time.now - start_time)
|
107
|
+
period_of_time_waited.should be >= timeout_in_seconds
|
108
|
+
end
|
109
|
+
|
62
110
|
end
|
63
111
|
|
64
112
|
end
|
65
113
|
|
66
|
-
|
114
|
+
context "when the block eventually returns false" do
|
67
115
|
|
68
116
|
it "should execute without error" do
|
69
117
|
invocation_count = 0
|
@@ -81,27 +129,51 @@ describe WaitUntil::Wait do
|
|
81
129
|
|
82
130
|
describe ".until!" do
|
83
131
|
|
84
|
-
|
132
|
+
context "when the block executes without error" do
|
133
|
+
|
134
|
+
let(:block) do
|
135
|
+
lambda { WaitUntil::Wait.until!("some operation") { } }
|
136
|
+
end
|
85
137
|
|
86
138
|
it "should execute without error" do
|
87
|
-
|
139
|
+
block.should_not raise_error
|
88
140
|
end
|
89
141
|
|
90
142
|
end
|
91
143
|
|
92
|
-
|
144
|
+
context "when the block raises an error indefinitely" do
|
93
145
|
|
94
|
-
|
146
|
+
let(:timeout_in_seconds) { nil }
|
147
|
+
let(:block) do
|
95
148
|
lambda do
|
96
|
-
WaitUntil::Wait.until!("some operation finishes") do
|
149
|
+
WaitUntil::Wait.until!("some operation finishes", timeout_in_seconds: timeout_in_seconds) do
|
97
150
|
raise "forced error"
|
98
151
|
end
|
99
|
-
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
it "should raise an error indicating the operation timed-out" do
|
156
|
+
block.should raise_error(/Timed-out waiting until 'some operation finishes'/i)
|
157
|
+
end
|
158
|
+
|
159
|
+
context "and a timeout is provided" do
|
160
|
+
|
161
|
+
let(:timeout_in_seconds) { 2 }
|
162
|
+
|
163
|
+
it "should wait until at least a period of time matching the timeout before raising an error" do
|
164
|
+
start_time = Time.now
|
165
|
+
|
166
|
+
block.should raise_error
|
167
|
+
|
168
|
+
period_of_time_waited = (Time.now - start_time)
|
169
|
+
period_of_time_waited.should be >= timeout_in_seconds
|
170
|
+
end
|
171
|
+
|
100
172
|
end
|
101
173
|
|
102
174
|
end
|
103
175
|
|
104
|
-
|
176
|
+
context "when the block eventually executes without error" do
|
105
177
|
|
106
178
|
it "should execute without error" do
|
107
179
|
invocation_count = 0
|
data/spec/spec_helper.rb
CHANGED
@@ -1,14 +1,11 @@
|
|
1
1
|
require 'simplecov'
|
2
2
|
SimpleCov.start do
|
3
3
|
add_filter "/spec/"
|
4
|
+
add_filter "/vendor/"
|
4
5
|
minimum_coverage 100
|
5
6
|
refuse_coverage_drop
|
6
7
|
end if ENV["coverage"]
|
7
8
|
|
8
9
|
require_relative "../lib/wait_until"
|
9
10
|
|
10
|
-
require 'rubygems'
|
11
|
-
require 'bundler'
|
12
|
-
Bundler.require(:test)
|
13
|
-
|
14
11
|
Dir[File.expand_path('../support/**/*.rb', __FILE__)].each { |file| require file }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wait_until
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,16 +9,16 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-11-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
15
|
+
name: travis-lint
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: '
|
21
|
+
version: '1.7'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -26,15 +26,15 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: '
|
29
|
+
version: '1.7'
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
|
-
name:
|
31
|
+
name: metric_fu
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
33
33
|
none: false
|
34
34
|
requirements:
|
35
35
|
- - ~>
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version:
|
37
|
+
version: '4.4'
|
38
38
|
type: :development
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -42,15 +42,15 @@ dependencies:
|
|
42
42
|
requirements:
|
43
43
|
- - ~>
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version:
|
45
|
+
version: '4.4'
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
|
-
name:
|
47
|
+
name: rspec
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
49
49
|
none: false
|
50
50
|
requirements:
|
51
51
|
- - ~>
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version:
|
53
|
+
version: '2.14'
|
54
54
|
type: :development
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -58,15 +58,31 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: '2.14'
|
62
62
|
- !ruby/object:Gem::Dependency
|
63
|
-
name:
|
63
|
+
name: rake
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '10.1'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '10.1'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: simplecov
|
64
80
|
requirement: !ruby/object:Gem::Requirement
|
65
81
|
none: false
|
66
82
|
requirements:
|
67
83
|
- - ~>
|
68
84
|
- !ruby/object:Gem::Version
|
69
|
-
version:
|
85
|
+
version: '0.7'
|
70
86
|
type: :development
|
71
87
|
prerelease: false
|
72
88
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -74,7 +90,7 @@ dependencies:
|
|
74
90
|
requirements:
|
75
91
|
- - ~>
|
76
92
|
- !ruby/object:Gem::Version
|
77
|
-
version:
|
93
|
+
version: '0.7'
|
78
94
|
description: Suspends execution until state changes via ::Wait.until! methods, timing-out
|
79
95
|
after a configured period of time
|
80
96
|
email: matthew.ueckerman@myob.com
|