@@ -30,24 +30,28 @@ def initialize
30
30
obligation . should be_incomplete
31
31
end
32
32
33
- describe '#value' do
33
+ methods = [ :value , :value! , :no_error! ]
34
+ methods . each do |method |
35
+ describe "##{ method } " do
34
36
35
- it 'should return immediately if timeout is zero' do
36
- obligation . value ( 0 ) . should be_nil
37
- end
37
+ it 'should return immediately if timeout is zero' do
38
+ obligation . send ( method , 0 ) . should ( method == :no_error! ? eq ( obligation ) : be_nil )
39
+ end
38
40
39
- it 'should block on the event if timeout is not set' do
40
- obligation . stub ( :event ) . and_return ( event )
41
- event . should_receive ( :wait ) . with ( nil )
41
+ it 'should block on the event if timeout is not set' do
42
+ obligation . stub ( :event ) . and_return ( event )
43
+ event . should_receive ( :wait ) . with ( nil )
42
44
43
- obligation . value
44
- end
45
+ obligation . send method
46
+ end
47
+
48
+ it 'should block on the event if timeout is not zero' do
49
+ obligation . stub ( :event ) . and_return ( event )
50
+ event . should_receive ( :wait ) . with ( 5 )
45
51
46
- it 'should block on the event if timeout is not zero' do
47
- obligation . stub ( :event ) . and_return ( event )
48
- event . should_receive ( :wait ) . with ( 5 )
52
+ obligation . send ( method , 5 )
53
+ end
49
54
50
- obligation . value ( 5 )
51
55
end
52
56
end
53
57
end
@@ -98,6 +102,45 @@ def initialize
98
102
99
103
end
100
104
105
+ describe '#value!' do
106
+
107
+ it 'should return immediately if timeout is zero' do
108
+ obligation . value! ( 0 ) . should eq 42
109
+ end
110
+
111
+ it 'should return immediately if timeout is not set' do
112
+ event . should_not_receive ( :wait )
113
+
114
+ obligation . value! . should eq 42
115
+ end
116
+
117
+ it 'should return immediately if timeout is not zero' do
118
+ event . should_not_receive ( :wait )
119
+
120
+ obligation . value! ( 5 ) . should eq 42
121
+ end
122
+
123
+ end
124
+
125
+ describe '#no_error!' do
126
+
127
+ it 'should return immediately if timeout is zero' do
128
+ obligation . no_error! ( 0 ) . should eq obligation
129
+ end
130
+
131
+ it 'should return immediately if timeout is not set' do
132
+ event . should_not_receive ( :wait )
133
+
134
+ obligation . no_error! . should eq obligation
135
+ end
136
+
137
+ it 'should return immediately if timeout is not zero' do
138
+ event . should_not_receive ( :wait )
139
+
140
+ obligation . no_error! ( 5 ) . should eq obligation
141
+ end
142
+
143
+ end
101
144
102
145
end
103
146
@@ -115,26 +158,72 @@ def initialize
115
158
it 'should be not incomplete' do
116
159
obligation . should_not be_incomplete
117
160
end
118
- end
119
161
120
- describe '#value' do
121
162
122
- it 'should return immediately if timeout is zero' do
123
- event . should_not_receive ( :wait )
163
+ describe '#value' do
164
+
165
+ it 'should return immediately if timeout is zero' do
166
+ event . should_not_receive ( :wait )
167
+
168
+ obligation . value ( 0 ) . should be_nil
169
+ end
170
+
171
+ it 'should return immediately if timeout is not set' do
172
+ event . should_not_receive ( :wait )
173
+
174
+ obligation . value . should be_nil
175
+ end
176
+
177
+ it 'should return immediately if timeout is not zero' do
178
+ event . should_not_receive ( :wait )
179
+
180
+ obligation . value ( 5 ) . should be_nil
181
+ end
124
182
125
- obligation . value ( 0 ) . should be_nil
126
183
end
127
184
128
- it 'should return immediately if timeout is not set' do
129
- event . should_not_receive ( :wait )
185
+ describe '#value!' do
186
+
187
+ it 'should return immediately if timeout is zero' do
188
+ event . should_not_receive ( :wait )
189
+
190
+ -> { obligation . value! ( 0 ) } . should raise_error
191
+ end
192
+
193
+ it 'should return immediately if timeout is not set' do
194
+ event . should_not_receive ( :wait )
195
+
196
+ -> { obligation . value! } . should raise_error
197
+ end
198
+
199
+ it 'should return immediately if timeout is not zero' do
200
+ event . should_not_receive ( :wait )
201
+
202
+ -> { obligation . value! ( 5 ) } . should raise_error
203
+ end
130
204
131
- obligation . value . should be_nil
132
205
end
133
206
134
- it 'should return immediately if timeout is not zero' do
135
- event . should_not_receive ( :wait )
207
+ describe '#no_error!' do
208
+
209
+ it 'should return immediately if timeout is zero' do
210
+ event . should_not_receive ( :wait )
211
+
212
+ -> { obligation . no_error! ( 0 ) } . should raise_error
213
+ end
214
+
215
+ it 'should return immediately if timeout is not set' do
216
+ event . should_not_receive ( :wait )
217
+
218
+ -> { obligation . no_error! } . should raise_error
219
+ end
220
+
221
+ it 'should return immediately if timeout is not zero' do
222
+ event . should_not_receive ( :wait )
223
+
224
+ -> { obligation . no_error! ( 5 ) } . should raise_error
225
+ end
136
226
137
- obligation . value ( 5 ) . should be_nil
138
227
end
139
228
140
229
end
0 commit comments