wait_until 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/wait_until/operation.rb +9 -6
- data/lib/wait_until/version.rb +1 -1
- data/lib/wait_until/wait.rb +6 -6
- data/spec/lib/wait_until/operation_spec.rb +49 -9
- data/spec/lib/wait_until/wait_spec.rb +56 -72
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a5c68a76d714894ee9485a1b5ac4912796483a0f
|
4
|
+
data.tar.gz: 0e2f8e3181b35e07be9db356b98fff21bc48cc1a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 206d00e29b59bda409e945970a93d7ba81b84337297c40f0e4adbd956830cf79615e1ff3dd00fdfeb4590b84e1120c3e3bdb3ea237e7263e5043045e843d68ac
|
7
|
+
data.tar.gz: d49ed27c88ae9885dbfa8d0689d9696ce37a2647980dfe5ef6633422e64848bd6479764b06f2a81562711a18fe13f74dc8c2d1c1824e5e965c18ac0deaaf2082
|
data/lib/wait_until/operation.rb
CHANGED
@@ -2,10 +2,11 @@ module WaitUntil
|
|
2
2
|
|
3
3
|
class Operation
|
4
4
|
|
5
|
-
def initialize(
|
6
|
-
@
|
7
|
-
@
|
8
|
-
@
|
5
|
+
def initialize(args)
|
6
|
+
@timeout_in_seconds = args[:timeout_in_seconds] || ::WaitUntil::Wait.default_timeout_in_seconds
|
7
|
+
@description = args[:description]
|
8
|
+
@failure_message = args[:failure_message]
|
9
|
+
@on_failure = args[:on_failure]
|
9
10
|
end
|
10
11
|
|
11
12
|
def eventually_true?(&block)
|
@@ -17,8 +18,10 @@ module WaitUntil
|
|
17
18
|
end
|
18
19
|
|
19
20
|
def failure_message
|
20
|
-
message =
|
21
|
-
message
|
21
|
+
message = @failure_message
|
22
|
+
message ||= "Timed-out waiting until '#{@description}'" if @description
|
23
|
+
message ||= "Timed-out waiting until operation completed"
|
24
|
+
message << "\nLast observed exception: #{@last_error}" if @last_error
|
22
25
|
message
|
23
26
|
end
|
24
27
|
|
data/lib/wait_until/version.rb
CHANGED
data/lib/wait_until/wait.rb
CHANGED
@@ -6,17 +6,17 @@ module WaitUntil
|
|
6
6
|
|
7
7
|
attr_accessor :default_timeout_in_seconds
|
8
8
|
|
9
|
-
def until_true!(
|
10
|
-
operation = WaitUntil::Operation.new(
|
9
|
+
def until_true!(args={}, &block)
|
10
|
+
operation = WaitUntil::Operation.new(args)
|
11
11
|
raise operation.failure_message unless operation.eventually_true?(&block)
|
12
12
|
end
|
13
13
|
|
14
|
-
def until_false!(
|
15
|
-
until_true!(
|
14
|
+
def until_false!(args={}, &block)
|
15
|
+
until_true!(args) { !block.call }
|
16
16
|
end
|
17
17
|
|
18
|
-
def until!(
|
19
|
-
until_true!(
|
18
|
+
def until!(args={}, &block)
|
19
|
+
until_true!(args) do
|
20
20
|
block.call
|
21
21
|
true
|
22
22
|
end
|
@@ -8,10 +8,9 @@ describe WaitUntil::Operation do
|
|
8
8
|
|
9
9
|
end
|
10
10
|
|
11
|
-
let(:
|
12
|
-
let(:options) { {} }
|
11
|
+
let(:args) { {} }
|
13
12
|
|
14
|
-
let(:operation) { described_class.new(
|
13
|
+
let(:operation) { described_class.new(args) }
|
15
14
|
|
16
15
|
before(:example) { InvocationData.counter = 0 }
|
17
16
|
|
@@ -53,7 +52,7 @@ describe WaitUntil::Operation do
|
|
53
52
|
context "and a timeout is provided" do
|
54
53
|
|
55
54
|
let(:timeout_in_seconds) { 2 }
|
56
|
-
let(:
|
55
|
+
let(:args) { { timeout_in_seconds: timeout_in_seconds } }
|
57
56
|
|
58
57
|
it "waits until at least that period of time before returning false" do
|
59
58
|
start_time = Time.now
|
@@ -69,7 +68,7 @@ describe WaitUntil::Operation do
|
|
69
68
|
context "and a failure callback is provided" do
|
70
69
|
|
71
70
|
let(:on_failure_callback) { lambda { InvocationData.counter += 1 } }
|
72
|
-
let(:
|
71
|
+
let(:args) { { on_failure: on_failure_callback } }
|
73
72
|
|
74
73
|
it "executes the callback once" do
|
75
74
|
subject
|
@@ -106,12 +105,53 @@ describe WaitUntil::Operation do
|
|
106
105
|
|
107
106
|
shared_examples_for "a standard failure message" do
|
108
107
|
|
109
|
-
|
110
|
-
|
108
|
+
context "and a custom failure message was provided" do
|
109
|
+
|
110
|
+
let(:failure_message) { "some failure message" }
|
111
|
+
let(:args) { { failure_message: failure_message } }
|
112
|
+
|
113
|
+
it "contains the failure message" do
|
114
|
+
expect(subject).to include(failure_message)
|
115
|
+
end
|
116
|
+
|
117
|
+
context "and an operation description was provided" do
|
118
|
+
|
119
|
+
let(:description) { "some operation description" }
|
120
|
+
let(:args) { { failure_message: failure_message, description: description } }
|
121
|
+
|
122
|
+
it "contains the failure message" do
|
123
|
+
expect(subject).to include(failure_message)
|
124
|
+
end
|
125
|
+
|
126
|
+
it "excludes the description" do
|
127
|
+
expect(subject).to_not include(description)
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|
131
|
+
|
111
132
|
end
|
112
133
|
|
113
|
-
|
114
|
-
|
134
|
+
context "and an operation description was provided" do
|
135
|
+
|
136
|
+
let(:description) { "some operation description" }
|
137
|
+
let(:args) { { description: description } }
|
138
|
+
|
139
|
+
it "indicates a time-out occurred" do
|
140
|
+
expect(subject).to include("Timed-out")
|
141
|
+
end
|
142
|
+
|
143
|
+
it "contains the description" do
|
144
|
+
expect(subject).to include(description)
|
145
|
+
end
|
146
|
+
|
147
|
+
end
|
148
|
+
|
149
|
+
context "and no failure message or description was provided" do
|
150
|
+
|
151
|
+
it "indicates a time-out occurred" do
|
152
|
+
expect(subject).to include("Timed-out")
|
153
|
+
end
|
154
|
+
|
115
155
|
end
|
116
156
|
|
117
157
|
end
|
@@ -1,26 +1,46 @@
|
|
1
1
|
describe WaitUntil::Wait do
|
2
2
|
|
3
|
-
let(:
|
4
|
-
let(:
|
3
|
+
let(:block) { lambda { "some block" } }
|
4
|
+
let(:args) { {} }
|
5
5
|
|
6
|
-
shared_examples_for "a wait method that
|
6
|
+
shared_examples_for "a wait method that uses an operation to determine if it eventually succeeds" do
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
let(:eventually_true_flag) { true }
|
9
|
+
let(:failure_message) { "some failure message" }
|
10
|
+
let(:operation) do
|
11
|
+
instance_double(WaitUntil::Operation, eventually_true?: eventually_true_flag, failure_message: failure_message)
|
10
12
|
end
|
11
13
|
|
12
|
-
|
14
|
+
before(:example) { allow(WaitUntil::Operation).to receive(:new).and_return(operation) }
|
13
15
|
|
14
|
-
|
15
|
-
|
16
|
+
it "creates an operation representing the call" do
|
17
|
+
expect(WaitUntil::Operation).to receive(:new).with(args)
|
16
18
|
|
17
|
-
|
18
|
-
|
19
|
+
subject
|
20
|
+
end
|
21
|
+
|
22
|
+
it "determines if the operation eventually returns true" do
|
23
|
+
expect(operation).to receive(:eventually_true?)
|
24
|
+
|
25
|
+
subject
|
26
|
+
end
|
27
|
+
|
28
|
+
context "when the operation is eventually true" do
|
19
29
|
|
20
|
-
|
30
|
+
let(:eventually_true_flag) { true }
|
21
31
|
|
22
|
-
|
23
|
-
expect(
|
32
|
+
it "executes without error" do
|
33
|
+
expect(lambda { subject }).to_not raise_error
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
context "when the operation is never eventually true" do
|
39
|
+
|
40
|
+
let(:eventually_true_flag) { false }
|
41
|
+
|
42
|
+
it "raises an error with the operations failure message" do
|
43
|
+
expect(lambda { subject }).to raise_error(failure_message)
|
24
44
|
end
|
25
45
|
|
26
46
|
end
|
@@ -29,38 +49,26 @@ describe WaitUntil::Wait do
|
|
29
49
|
|
30
50
|
describe "::until_true!" do
|
31
51
|
|
32
|
-
subject {
|
52
|
+
subject { described_class.until_true!(args, &block) }
|
53
|
+
|
54
|
+
it_behaves_like "a wait method that uses an operation to determine if it eventually succeeds"
|
33
55
|
|
34
56
|
context "when the block returns true" do
|
35
57
|
|
36
58
|
let(:block) { lambda { true } }
|
37
59
|
|
38
60
|
it "executes without error" do
|
39
|
-
expect(subject).to_not raise_error
|
61
|
+
expect(lambda { subject }).to_not raise_error
|
40
62
|
end
|
41
63
|
|
42
64
|
end
|
43
65
|
|
44
|
-
context "when the
|
66
|
+
context "when the block returns false" do
|
45
67
|
|
46
68
|
let(:block) { lambda { false } }
|
47
69
|
|
48
|
-
|
49
|
-
|
50
|
-
end
|
51
|
-
|
52
|
-
context "when the block eventually returns true" do
|
53
|
-
|
54
|
-
let(:block) do
|
55
|
-
invocation_count = 0
|
56
|
-
lambda do
|
57
|
-
invocation_count += 1
|
58
|
-
invocation_count == 3
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
it "executes without error" do
|
63
|
-
expect(subject).to_not raise_error
|
70
|
+
it "raises an error" do
|
71
|
+
expect(lambda { subject }).to raise_error(/timed-out/i)
|
64
72
|
end
|
65
73
|
|
66
74
|
end
|
@@ -69,38 +77,26 @@ describe WaitUntil::Wait do
|
|
69
77
|
|
70
78
|
describe "::until_false!" do
|
71
79
|
|
72
|
-
subject {
|
80
|
+
subject { described_class.until_false!(args, &block) }
|
81
|
+
|
82
|
+
it_behaves_like "a wait method that uses an operation to determine if it eventually succeeds"
|
73
83
|
|
74
84
|
context "when the block returns false" do
|
75
85
|
|
76
86
|
let(:block) { lambda { false } }
|
77
87
|
|
78
88
|
it "executes without error" do
|
79
|
-
expect(subject).to_not raise_error
|
89
|
+
expect(lambda { subject }).to_not raise_error
|
80
90
|
end
|
81
91
|
|
82
92
|
end
|
83
93
|
|
84
|
-
context "when the
|
94
|
+
context "when the block returns true" do
|
85
95
|
|
86
96
|
let(:block) { lambda { true } }
|
87
97
|
|
88
|
-
|
89
|
-
|
90
|
-
end
|
91
|
-
|
92
|
-
context "when the block eventually returns false" do
|
93
|
-
|
94
|
-
let(:block) do
|
95
|
-
invocation_count = 0
|
96
|
-
lambda do
|
97
|
-
invocation_count += 1
|
98
|
-
invocation_count < 3
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
it "executes without error" do
|
103
|
-
expect(subject).to_not raise_error
|
98
|
+
it "raises an error" do
|
99
|
+
expect(lambda { subject }).to raise_error(/timed-out/i)
|
104
100
|
end
|
105
101
|
|
106
102
|
end
|
@@ -109,38 +105,26 @@ describe WaitUntil::Wait do
|
|
109
105
|
|
110
106
|
describe "::until!" do
|
111
107
|
|
112
|
-
subject {
|
108
|
+
subject { described_class.until!(args, &block) }
|
109
|
+
|
110
|
+
it_behaves_like "a wait method that uses an operation to determine if it eventually succeeds"
|
113
111
|
|
114
112
|
context "when the block executes without error" do
|
115
113
|
|
116
|
-
let(:block) { lambda {
|
114
|
+
let(:block) { lambda { "does not raise an error" } }
|
117
115
|
|
118
116
|
it "executes without error" do
|
119
|
-
expect(subject).to_not raise_error
|
117
|
+
expect(lambda { subject }).to_not raise_error
|
120
118
|
end
|
121
119
|
|
122
120
|
end
|
123
121
|
|
124
|
-
context "when the block raises an error
|
125
|
-
|
126
|
-
let(:block) { lambda { raise "Forced Error" } }
|
122
|
+
context "when the block raises an error" do
|
127
123
|
|
128
|
-
|
129
|
-
|
130
|
-
end
|
124
|
+
let(:block) { lambda { raise "forced error" } }
|
131
125
|
|
132
|
-
|
133
|
-
|
134
|
-
let(:block) do
|
135
|
-
invocation_count = 0
|
136
|
-
lambda do
|
137
|
-
invocation_count += 1
|
138
|
-
raise "Forced Error" if invocation_count < 3
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
it "executes without error" do
|
143
|
-
expect(subject).to_not raise_error
|
126
|
+
it "raises an error" do
|
127
|
+
expect(lambda { subject }).to raise_error(/timed-out/i)
|
144
128
|
end
|
145
129
|
|
146
130
|
end
|