-
Notifications
You must be signed in to change notification settings - Fork 67
/
add_to_context_spec.rb
57 lines (46 loc) · 1.39 KB
/
add_to_context_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
50
51
52
53
54
55
56
57
require 'spec_helper'
RSpec.describe LightService::Organizer do
class TestAddToContext
extend LightService::Organizer
def self.call(context = LightService::Context.make)
with(context).reduce(steps)
end
def self.steps
[
# This will add the `:number` key to the context
# with the value of 0, so it's available for
# AddsOneAction
add_to_context(:number => 0),
TestDoubles::AddsOneAction,
add_to_context(:something => 'hello')
]
end
end
class TestAddToContextReservedWords
extend LightService::Organizer
def self.call(context = LightService::Context.make)
with(context).reduce(steps)
end
def self.steps
[
add_to_context(:message => "yo", "error_code" => "00P5")
]
end
end
it 'adds items to the context on the fly' do
result = TestAddToContext.call
expect(result).to be_success
expect(result.number).to eq(1)
expect(result[:something]).to eq('hello')
end
it 'adds items to the context as accessors' do
result = TestAddToContext.call
expect(result).to be_success
expect(result.something).to eq('hello')
end
it "will not add items as accessors when they are reserved" do
expect { TestAddToContextReservedWords.call }.to \
raise_error(LightService::ReservedKeysInContextError)
.with_message(/:message, :error_code/)
end
end