@@ -30,24 +30,28 @@ def initialize
3030 obligation . should be_incomplete
3131 end
3232
33- describe '#value' do
33+ methods = [ :value , :value! , :no_error! ]
34+ methods . each do |method |
35+ describe "##{ method } " do
3436
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
3840
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 )
4244
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 )
4551
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
4954
50- obligation . value ( 5 )
5155 end
5256 end
5357 end
@@ -98,6 +102,45 @@ def initialize
98102
99103 end
100104
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
101144
102145 end
103146
@@ -115,26 +158,72 @@ def initialize
115158 it 'should be not incomplete' do
116159 obligation . should_not be_incomplete
117160 end
118- end
119161
120- describe '#value' do
121162
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
124182
125- obligation . value ( 0 ) . should be_nil
126183 end
127184
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
130204
131- obligation . value . should be_nil
132205 end
133206
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
136226
137- obligation . value ( 5 ) . should be_nil
138227 end
139228
140229 end
0 commit comments