-
Notifications
You must be signed in to change notification settings - Fork 67
/
reduce_until_spec.rb
49 lines (37 loc) · 1.16 KB
/
reduce_until_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
require 'spec_helper'
require 'test_doubles'
RSpec.describe LightService::Organizer do
class TestReduceUntil
extend LightService::Organizer
def self.call(context)
with(context).reduce(actions)
end
def self.actions
[
reduce_until(->(ctx) { ctx.number == 3 },
TestDoubles::AddsOneAction)
]
end
end
let(:empty_context) { LightService::Context.make }
it 'reduces until the block evaluates to true' do
context = { :number => 1 }
result = TestReduceUntil.call(context)
expect(result).to be_success
expect(result.number).to eq(3)
end
it 'does not execute on failed context' do
empty_context.fail!('Something bad happened')
result = TestReduceUntil.call(empty_context)
expect(result).to be_failure
end
it 'does not execute a skipped context' do
empty_context.skip_remaining!('No more needed')
result = TestReduceUntil.call(empty_context)
expect(result).to be_success
end
it "is expected to know its organizer when reducing until a condition" do
result = TestReduceUntil.call(:number => 1)
expect(result.organized_by).to eq TestReduceUntil
end
end