Skip to content

Commit eba0925

Browse files
committed
Adding test for various all and any permutations
1 parent 697b38d commit eba0925

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

spec/workflow/future_spec.rb

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,60 @@
9696
then_future.wait
9797
expect(then_future.value).to eq('Hello, Bob')
9898
end
99+
100+
describe 'aggregations' do
101+
it 'can pass on all' do
102+
f1 = Factor::Workflow::Future.new { 'a' }
103+
f2 = Factor::Workflow::Future.new { 'a' }
104+
105+
f_all = Factor::Workflow::Future.all(f1,f2) { |f| f == 'a' }
106+
f_all.wait
107+
108+
expect(f_all.value).to be true
109+
end
110+
111+
it 'can fail on all' do
112+
f1 = Factor::Workflow::Future.new { 'a' }
113+
f2 = Factor::Workflow::Future.new { 'b' }
114+
115+
f_all = Factor::Workflow::Future.all(f1,f2) { |f| f == 'a' }
116+
f_all.wait
117+
118+
expect(f_all.state).to be :rejected
119+
expect(f_all.reason).to be_a(StandardError)
120+
expect(f_all.reason.message).to eq('There were no successful events')
121+
end
122+
123+
it 'can pass on any with all true' do
124+
f1 = Factor::Workflow::Future.new { 'a' }
125+
f2 = Factor::Workflow::Future.new { 'a' }
126+
127+
f_any = Factor::Workflow::Future.any(f1,f2) { |f| f == 'a' }
128+
f_any.wait
129+
130+
expect(f_any.value).to be true
131+
end
132+
133+
it 'can pass on any with one true' do
134+
f1 = Factor::Workflow::Future.new { 'a' }
135+
f2 = Factor::Workflow::Future.new { 'b' }
136+
137+
f_any = Factor::Workflow::Future.any(f1,f2) { |f| f == 'a' }
138+
f_any.wait
139+
140+
expect(f_any.value).to be true
141+
end
142+
143+
it 'can fail on any' do
144+
f1 = Factor::Workflow::Future.new { 'b' }
145+
f2 = Factor::Workflow::Future.new { 'b' }
146+
147+
f_any = Factor::Workflow::Future.any(f1,f2) { |f| f == 'a' }
148+
f_any.wait
149+
150+
expect(f_any.state).to be :rejected
151+
expect(f_any.reason).to be_a(StandardError)
152+
expect(f_any.reason.message).to eq('There were no successful events')
153+
end
154+
end
99155
end

0 commit comments

Comments
 (0)