substation 0.0.10.beta2 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (167) hide show
  1. data/.travis.yml +7 -3
  2. data/Changelog.md +99 -24
  3. data/Gemfile +8 -1
  4. data/Gemfile.devtools +37 -21
  5. data/Guardfile +1 -1
  6. data/README.md +118 -46
  7. data/TODO.md +1 -0
  8. data/config/flay.yml +2 -2
  9. data/config/flog.yml +1 -1
  10. data/config/reek.yml +41 -16
  11. data/config/rubocop.yml +44 -0
  12. data/config/yardstick.yml +1 -1
  13. data/lib/substation.rb +41 -5
  14. data/lib/substation/chain.rb +73 -84
  15. data/lib/substation/chain/definition.rb +147 -0
  16. data/lib/substation/chain/dsl.rb +150 -112
  17. data/lib/substation/chain/dsl/config.rb +55 -0
  18. data/lib/substation/chain/dsl/module_builder.rb +84 -0
  19. data/lib/substation/dispatcher.rb +20 -229
  20. data/lib/substation/dsl/guard.rb +96 -0
  21. data/lib/substation/dsl/registry.rb +181 -0
  22. data/lib/substation/environment.rb +126 -23
  23. data/lib/substation/environment/dsl.rb +31 -12
  24. data/lib/substation/processor.rb +238 -7
  25. data/lib/substation/processor/builder.rb +26 -0
  26. data/lib/substation/processor/config.rb +24 -0
  27. data/lib/substation/processor/evaluator.rb +66 -42
  28. data/lib/substation/processor/evaluator/handler.rb +54 -0
  29. data/lib/substation/processor/evaluator/result.rb +24 -0
  30. data/lib/substation/processor/executor.rb +46 -0
  31. data/lib/substation/processor/nest.rb +40 -0
  32. data/lib/substation/processor/transformer.rb +46 -0
  33. data/lib/substation/processor/wrapper.rb +16 -5
  34. data/lib/substation/request.rb +29 -27
  35. data/lib/substation/response.rb +19 -34
  36. data/lib/substation/response/api.rb +37 -0
  37. data/lib/substation/response/exception.rb +20 -0
  38. data/lib/substation/response/exception/output.rb +59 -0
  39. data/lib/substation/response/failure.rb +11 -0
  40. data/lib/substation/response/success.rb +11 -0
  41. data/lib/substation/version.rb +3 -1
  42. data/spec/demo/core.rb +64 -0
  43. data/spec/demo/core/action.rb +49 -0
  44. data/spec/demo/core/action/create_person.rb +28 -0
  45. data/spec/demo/core/errors.rb +16 -0
  46. data/spec/demo/core/facade.rb +38 -0
  47. data/spec/demo/core/handler.rb +21 -0
  48. data/spec/demo/core/handler/acceptor.rb +47 -0
  49. data/spec/demo/core/handler/authenticator.rb +36 -0
  50. data/spec/demo/core/handler/authorizer.rb +38 -0
  51. data/spec/demo/core/input.rb +15 -0
  52. data/spec/demo/core/observers.rb +10 -0
  53. data/spec/demo/core/validator.rb +21 -0
  54. data/spec/demo/domain/actor.rb +29 -0
  55. data/spec/demo/domain/dto/person.rb +18 -0
  56. data/spec/demo/domain/environment.rb +55 -0
  57. data/spec/demo/domain/storage.rb +49 -0
  58. data/spec/demo/web.rb +26 -0
  59. data/spec/demo/web/errors.rb +9 -0
  60. data/spec/demo/web/facade.rb +60 -0
  61. data/spec/demo/web/handler/deserializer.rb +36 -0
  62. data/spec/demo/web/presenter.rb +38 -0
  63. data/spec/demo/web/presenter/person.rb +19 -0
  64. data/spec/demo/web/renderer.rb +45 -0
  65. data/spec/demo/web/sanitizer.rb +35 -0
  66. data/spec/demo/web/sanitizer/person.rb +20 -0
  67. data/spec/demo/web/views.rb +28 -0
  68. data/spec/integration/demo/core_spec.rb +97 -0
  69. data/spec/integration/demo/web_spec.rb +114 -0
  70. data/spec/shared/context/integration/demo.rb +33 -0
  71. data/spec/shared/context/unit/chain.rb +13 -0
  72. data/spec/shared/context/unit/processor.rb +58 -0
  73. data/spec/shared/context/unit/request.rb +8 -0
  74. data/spec/shared/examples/integration/demo.rb +35 -0
  75. data/spec/shared/examples/unit/processor.rb +72 -0
  76. data/spec/spec_helper.rb +52 -23
  77. data/spec/unit/substation/chain/definition_spec.rb +141 -0
  78. data/spec/unit/substation/chain/dsl/config/dsl_module_spec.rb +13 -0
  79. data/spec/unit/substation/chain/dsl/config/registry_spec.rb +13 -0
  80. data/spec/unit/substation/chain/dsl/config_spec.rb +18 -0
  81. data/spec/unit/substation/chain/dsl/module_builder_spec.rb +77 -0
  82. data/spec/unit/substation/chain/dsl_spec.rb +175 -0
  83. data/spec/unit/substation/chain_spec.rb +303 -0
  84. data/spec/unit/substation/dispatcher_spec.rb +68 -0
  85. data/spec/unit/substation/dsl/guard_spec.rb +72 -0
  86. data/spec/unit/substation/dsl/registry_spec.rb +181 -0
  87. data/spec/unit/substation/environment/dsl_spec.rb +156 -0
  88. data/spec/unit/substation/environment_spec.rb +259 -0
  89. data/spec/unit/substation/processor/builder_spec.rb +21 -0
  90. data/spec/unit/substation/processor/config_spec.rb +40 -0
  91. data/spec/unit/substation/processor/evaluator/handler_spec.rb +20 -0
  92. data/spec/unit/substation/processor/evaluator/pivot_spec.rb +42 -0
  93. data/spec/unit/substation/processor/evaluator/request_spec.rb +11 -0
  94. data/spec/unit/substation/processor/evaluator/result/failure_spec.rb +14 -0
  95. data/spec/unit/substation/processor/evaluator/result/success_spec.rb +14 -0
  96. data/spec/unit/substation/processor/evaluator/result_spec.rb +13 -0
  97. data/spec/unit/substation/processor/evaluator_spec.rb +18 -0
  98. data/spec/unit/substation/processor/executor/null_spec.rb +25 -0
  99. data/spec/unit/substation/processor/executor_spec.rb +32 -0
  100. data/spec/unit/substation/processor/fallible_spec.rb +24 -0
  101. data/spec/unit/substation/processor/incoming_spec.rb +17 -0
  102. data/spec/unit/substation/processor/nest/incoming_spec.rb +56 -0
  103. data/spec/unit/substation/processor/nest_spec.rb +6 -0
  104. data/spec/unit/substation/processor/outgoing_spec.rb +47 -0
  105. data/spec/unit/substation/processor/transformer/incoming_spec.rb +17 -0
  106. data/spec/unit/substation/processor/transformer/outgoing_spec.rb +17 -0
  107. data/spec/unit/substation/processor/wrapper/incoming_spec.rb +15 -0
  108. data/spec/unit/substation/processor/wrapper/outgoing_spec.rb +15 -0
  109. data/spec/unit/substation/processor/wrapper_spec.rb +24 -0
  110. data/spec/unit/substation/processor_spec.rb +68 -0
  111. data/spec/unit/substation/request_spec.rb +70 -0
  112. data/spec/unit/substation/response/api_spec.rb +22 -0
  113. data/spec/unit/substation/response/exception/output_spec.rb +46 -0
  114. data/spec/unit/substation/response/exception_spec.rb +25 -0
  115. data/spec/unit/substation/response/failure_spec.rb +25 -0
  116. data/spec/unit/substation/response/success_spec.rb +24 -0
  117. data/spec/unit/substation/response_spec.rb +73 -0
  118. data/substation.gemspec +7 -6
  119. metadata +157 -67
  120. checksums.yaml +0 -7
  121. data/TODO +0 -0
  122. data/lib/substation/observer.rb +0 -66
  123. data/lib/substation/processor/pivot.rb +0 -25
  124. data/lib/substation/utils.rb +0 -68
  125. data/spec/integration/substation/dispatcher/call_spec.rb +0 -260
  126. data/spec/unit/substation/chain/call_spec.rb +0 -63
  127. data/spec/unit/substation/chain/dsl/builder/class_methods/call_spec.rb +0 -19
  128. data/spec/unit/substation/chain/dsl/builder/dsl_spec.rb +0 -21
  129. data/spec/unit/substation/chain/dsl/builder/failure_chain_spec.rb +0 -30
  130. data/spec/unit/substation/chain/dsl/chain_spec.rb +0 -15
  131. data/spec/unit/substation/chain/dsl/class_methods/processors_spec.rb +0 -24
  132. data/spec/unit/substation/chain/dsl/initialize_spec.rb +0 -19
  133. data/spec/unit/substation/chain/dsl/processors_spec.rb +0 -42
  134. data/spec/unit/substation/chain/dsl/use_spec.rb +0 -14
  135. data/spec/unit/substation/chain/each_spec.rb +0 -46
  136. data/spec/unit/substation/chain/incoming/result_spec.rb +0 -21
  137. data/spec/unit/substation/chain/outgoing/call_spec.rb +0 -25
  138. data/spec/unit/substation/chain/outgoing/result_spec.rb +0 -21
  139. data/spec/unit/substation/dispatcher/action/call_spec.rb +0 -23
  140. data/spec/unit/substation/dispatcher/action/class_methods/coerce_spec.rb +0 -61
  141. data/spec/unit/substation/dispatcher/action_names_spec.rb +0 -14
  142. data/spec/unit/substation/dispatcher/call_spec.rb +0 -47
  143. data/spec/unit/substation/dispatcher/class_methods/coerce_spec.rb +0 -20
  144. data/spec/unit/substation/environment/chain_spec.rb +0 -50
  145. data/spec/unit/substation/environment/class_methods/build_spec.rb +0 -11
  146. data/spec/unit/substation/environment/dsl/class_methods/registry_spec.rb +0 -18
  147. data/spec/unit/substation/environment/dsl/register_spec.rb +0 -14
  148. data/spec/unit/substation/environment/dsl/registry_spec.rb +0 -19
  149. data/spec/unit/substation/observer/chain/call_spec.rb +0 -26
  150. data/spec/unit/substation/observer/class_methods/coerce_spec.rb +0 -33
  151. data/spec/unit/substation/observer/null/call_spec.rb +0 -12
  152. data/spec/unit/substation/processor/evaluator/call_spec.rb +0 -49
  153. data/spec/unit/substation/processor/pivot/call_spec.rb +0 -17
  154. data/spec/unit/substation/processor/wrapper/call_spec.rb +0 -20
  155. data/spec/unit/substation/request/env_spec.rb +0 -14
  156. data/spec/unit/substation/request/error_spec.rb +0 -15
  157. data/spec/unit/substation/request/input_spec.rb +0 -14
  158. data/spec/unit/substation/request/success_spec.rb +0 -15
  159. data/spec/unit/substation/response/env_spec.rb +0 -16
  160. data/spec/unit/substation/response/failure/success_predicate_spec.rb +0 -15
  161. data/spec/unit/substation/response/input_spec.rb +0 -16
  162. data/spec/unit/substation/response/output_spec.rb +0 -16
  163. data/spec/unit/substation/response/request_spec.rb +0 -16
  164. data/spec/unit/substation/response/success/success_predicate_spec.rb +0 -15
  165. data/spec/unit/substation/utils/class_methods/coerce_callable_spec.rb +0 -46
  166. data/spec/unit/substation/utils/class_methods/const_get_spec.rb +0 -46
  167. data/spec/unit/substation/utils/class_methods/symbolize_keys_spec.rb +0 -20
@@ -0,0 +1,156 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Substation::Environment::DSL do
6
+ describe '.registry' do
7
+ context 'when a block is given' do
8
+ let(:expected) {
9
+ DSL::Registry.new(guard, {
10
+ :test => Processor::Builder.new(:test, Spec::Processor, Processor::Executor::NULL)
11
+ })
12
+ }
13
+
14
+ let(:block) { ->(_) { register :test, Spec::Processor } }
15
+
16
+ let(:processor_name) { :test }
17
+ let(:registry) { Hash.new }
18
+
19
+ context 'and no guard is given' do
20
+ subject { described_class.registry(&block) }
21
+
22
+ let(:guard) { described_class::GUARD }
23
+
24
+ it { should eql(expected) }
25
+ end
26
+
27
+ context 'and a guard is given' do
28
+ subject { described_class.registry(guard, &block) }
29
+
30
+ let(:guard) { double('guard') }
31
+
32
+ # FIXME: this expectation should also be specified in the above
33
+ # context but since Guard includes Adamantium::Flat, setting a
34
+ # method expectation on it doesn't work
35
+ before do
36
+ expect(guard).to receive(:call).with(processor_name, registry)
37
+ end
38
+
39
+ it { should eql(expected) }
40
+ end
41
+ end
42
+
43
+ context 'when no block is given' do
44
+ subject { described_class.registry }
45
+
46
+ let(:expected) { DSL::Registry.new(guard) }
47
+
48
+ context 'and no guard is given' do
49
+ subject { described_class.registry }
50
+
51
+ let(:guard) { described_class::GUARD }
52
+
53
+ it { should eql(expected) }
54
+ end
55
+
56
+ context 'and a guard is given' do
57
+ subject { described_class.registry(guard) }
58
+
59
+ let(:guard) { double('guard') }
60
+
61
+ # FIXME: this expectation should also be specified in the above
62
+ # context but since Guard includes Adamantium::Flat, setting a
63
+ # method expectation on it doesn't work
64
+ before do
65
+ expect(guard).to_not receive(:call)
66
+ end
67
+
68
+ it { should eql(expected) }
69
+ end
70
+ end
71
+ end
72
+
73
+ describe '#register' do
74
+ subject { object.register(name, processor) }
75
+
76
+ let(:object) { described_class.new(registry) }
77
+ let(:registry) { DSL::Registry.new(guard) }
78
+ let(:guard) { described_class::GUARD }
79
+ let(:processor) { Spec::Processor }
80
+
81
+ let(:expected) {
82
+ DSL::Registry.new(guard, {
83
+ :test => Processor::Builder.new(:test, Spec::Processor, Processor::Executor::NULL)
84
+ })
85
+ }
86
+
87
+ context 'when the given name is valid' do
88
+
89
+ shared_examples 'name is valid' do
90
+ its(:registry) { should eql(expected) }
91
+
92
+ it_behaves_like 'a command method'
93
+ end
94
+
95
+ context 'and the name is given as a Symbol' do
96
+ it_behaves_like 'name is valid' do
97
+ let(:name) { :test }
98
+ end
99
+ end
100
+
101
+ context 'and the name is given as a String' do
102
+ it_behaves_like 'name is valid' do
103
+ let(:name) { 'test' }
104
+ end
105
+ end
106
+
107
+ end
108
+
109
+ context 'when the given name is reserved' do
110
+ let(:name) { Chain::DSL::BASE_METHODS.first }
111
+ let(:msg) { DSL::Guard::RESERVED_NAME_MSG % name.inspect }
112
+
113
+ it 'raises ReservedNameError' do
114
+ expect { subject }.to raise_error(ReservedNameError, msg)
115
+ end
116
+ end
117
+
118
+ context 'when the given name is already registered' do
119
+ let(:name) { :test }
120
+ let(:msg) { DSL::Guard::ALREADY_REGISTERED_MSG % name.inspect }
121
+
122
+ before do
123
+ object.register(name, processor)
124
+ end
125
+
126
+ it 'raises ReservedNameError' do
127
+ expect { subject }.to raise_error(AlreadyRegisteredError, msg)
128
+ end
129
+ end
130
+ end
131
+
132
+ describe '#registry' do
133
+ subject { object.registry }
134
+
135
+ let(:registry) { DSL::Registry.new(guard) }
136
+ let(:guard) { described_class::GUARD }
137
+
138
+ context 'when a block is given' do
139
+ let(:object) { described_class.new(registry, &block) }
140
+ let(:block) { ->(_) { register :test, Spec::Processor } }
141
+ let(:expected) {
142
+ DSL::Registry.new(guard, {
143
+ :test => Processor::Builder.new(:test, Spec::Processor, Processor::Executor::NULL)
144
+ })
145
+ }
146
+
147
+ it { should eql(expected) }
148
+ end
149
+
150
+ context 'when no block is given' do
151
+ let(:object) { described_class.new(registry) }
152
+
153
+ it { should eql(registry) }
154
+ end
155
+ end
156
+ end
@@ -0,0 +1,259 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Environment do
6
+ let(:object) { described_class.new(app_env, actions, chain_dsl) }
7
+ let(:app_env) { double('app_env') }
8
+ let(:actions) { Dispatcher.new_registry }
9
+ let(:registry) { double('registry') }
10
+
11
+ describe '#actions' do
12
+ subject { object.actions }
13
+
14
+ let(:chain_dsl) { double('app_env', :registry => registry) }
15
+
16
+ it { should be(actions) }
17
+ end
18
+
19
+ describe '#app_env' do
20
+ subject { object.app_env }
21
+
22
+ let(:chain_dsl) { double('app_env', :registry => registry) }
23
+
24
+ it { should be(app_env) }
25
+ end
26
+
27
+ describe '#chain' do
28
+ let(:chain_dsl) { Chain::DSL.build(registry) }
29
+ let(:registry) { described_class::DSL.registry(&r_block) }
30
+ let(:r_block) { ->(_) { register(:test, Spec::Processor) } }
31
+
32
+ let(:other) { double('other', :each => EMPTY_ARRAY) }
33
+ let(:failure_chain) { double('failure_chain') }
34
+ let(:block) { ->(_) { test Spec::FAKE_HANDLER, Chain::EMPTY } }
35
+
36
+ let(:name) { double('name') }
37
+
38
+ context 'when other, failure_chain and block are given' do
39
+ subject { object.chain(name, other, failure_chain, &block) }
40
+
41
+ it { should eql(chain_dsl.build(name, other, failure_chain, &block)) }
42
+ end
43
+
44
+ context 'when other, failure_chain and no block are given' do
45
+ subject { object.chain(name, other, failure_chain) }
46
+
47
+ it { should eql(chain_dsl.build(name, other, failure_chain)) }
48
+ end
49
+
50
+ context 'when other, no failure_chain and no block are given' do
51
+ subject { object.chain(name, other) }
52
+
53
+ it { should eql(chain_dsl.build(name, other, Chain::EMPTY)) }
54
+ end
55
+
56
+ context 'when no parameters are given' do
57
+ subject { object.chain }
58
+
59
+ it { should eql(chain_dsl.build(nil, Chain::EMPTY, Chain::EMPTY)) }
60
+ end
61
+ end
62
+
63
+ describe '#dispatcher' do
64
+ subject { object.dispatcher }
65
+
66
+ let(:chain_dsl) { double('chain_dsl', :registry => registry) }
67
+
68
+ let(:expected) { Dispatcher.new(actions, app_env) }
69
+
70
+ it { should eql(expected) }
71
+ end
72
+
73
+ describe '#[]' do
74
+ subject { object[name] }
75
+
76
+ let(:name) { double('name', :to_sym => :test) }
77
+ let(:chain_dsl) { Chain::DSL.build(described_class::DSL.registry(&block)) }
78
+ let(:block) { ->(_) { register(:test, Spec::Processor) } }
79
+
80
+ let(:chain) { chain_dsl.build(name, other, failure_chain, &chain_block) }
81
+ let(:other) { Chain::EMPTY }
82
+ let(:failure_chain) { Chain::EMPTY }
83
+ let(:chain_block) { ->(_) { test(Spec::FAKE_HANDLER) } }
84
+
85
+ context 'when a chain is registered under name' do
86
+ before do
87
+ object.register(name, &chain_block)
88
+ end
89
+
90
+ it { should eql(chain) }
91
+ end
92
+
93
+ context 'when no chain is registered under name' do
94
+ it 'raises an error' do
95
+ expect { subject }.to raise_error(KeyError)
96
+ end
97
+ end
98
+ end
99
+
100
+ describe 'equalizer behavior' do
101
+ subject { object == other }
102
+
103
+
104
+ let(:chain_dsl) { double('chain_dsl', :registry => registry) }
105
+
106
+ let(:other) { described_class.new(app_env, actions, other_chain_dsl) }
107
+ let(:other_chain_dsl) {
108
+ double('other_chain_dsl', :registry => other_registry)
109
+ }
110
+
111
+ context 'with an equal registry' do
112
+ let(:other_registry) { registry }
113
+
114
+ it { should be(true) }
115
+ end
116
+
117
+ context 'with a different registry' do
118
+ let(:other_registry) { double('other_registry') }
119
+
120
+ it { should be(false) }
121
+ end
122
+ end
123
+
124
+ describe '#inherit' do
125
+
126
+ let(:chain_dsl) { Chain::DSL.build(described_class::DSL.registry(&env_block)) }
127
+ let(:env_block) {
128
+ ->(_) {
129
+ register(:test_1, Spec::Processor)
130
+ register(:test_2, Spec::Processor)
131
+ }
132
+ }
133
+
134
+ let(:expected) { described_class.build(app_env, actions, &expected_block) }
135
+
136
+ let(:expected_block) {
137
+ ->(_) {
138
+ register(:test_1, Spec::Processor)
139
+ register(:test_2, Spec::Processor)
140
+ register(:test_3, Spec::Processor)
141
+ }
142
+ }
143
+
144
+ let(:block) {
145
+ ->(_) {
146
+ register(:test_3, Spec::Processor)
147
+ }
148
+ }
149
+
150
+ context 'when no app_env and actions are given' do
151
+ subject { object.inherit(&block) }
152
+
153
+ let(:new_actions) { Dispatcher.new_registry }
154
+
155
+ it { should eql(expected) }
156
+
157
+ its(:app_env) { should eql(app_env) }
158
+ its(:actions) { should eql(new_actions) }
159
+ end
160
+
161
+ context 'when app_env is given' do
162
+ subject { object.inherit(new_app_env, &block) }
163
+
164
+ let(:expected) { described_class.build(new_app_env, actions, &expected_block) }
165
+ let(:new_app_env) { double('new_app_env') }
166
+ let(:new_actions) { Dispatcher.new_registry }
167
+
168
+ it { should eql(expected) }
169
+
170
+ its(:app_env) { should eql(new_app_env) }
171
+ its(:actions) { should eql(new_actions) }
172
+ end
173
+
174
+ context 'when app_env and actions are given' do
175
+ subject { object.inherit(app_env, new_actions, &block) }
176
+
177
+ let(:new_actions) { double('new_actions') }
178
+
179
+ it { should eql(expected) }
180
+
181
+ its(:app_env) { should eql(app_env) }
182
+ its(:actions) { should be(new_actions) }
183
+ end
184
+ end
185
+
186
+ describe '#register' do
187
+ let(:chain_dsl) { Chain::DSL.build(described_class::DSL.registry(&block)) }
188
+ let(:block) { ->(_) { register(:test, Spec::Processor) } }
189
+
190
+ let(:chain_block) { ->(_) { test(Spec::FAKE_HANDLER) } }
191
+
192
+ let(:name) { double('name', :to_sym => :test) }
193
+ let(:other) { Chain::EMPTY }
194
+ let(:failure_chain) { double }
195
+
196
+ shared_examples 'Environment#register' do
197
+ it_behaves_like 'a command method'
198
+
199
+ it 'registers the chain under the given name' do
200
+ subject
201
+ expect(object[name]).to eql(chain)
202
+ end
203
+ end
204
+
205
+ context 'when other and failure_chain are not given' do
206
+ subject { object.register(name, &chain_block) }
207
+
208
+ let(:chain) { chain_dsl.build(name, Chain::EMPTY, Chain::EMPTY, &chain_block) }
209
+
210
+ it_behaves_like 'Environment#register'
211
+ end
212
+
213
+ context 'when other is given and failure_chain is not given' do
214
+ subject { object.register(name, other, &chain_block) }
215
+
216
+ let(:chain) { chain_dsl.build(name, other, Chain::EMPTY, &chain_block) }
217
+
218
+ it_behaves_like 'Environment#register'
219
+ end
220
+
221
+ context 'when both other and failure_chain are given' do
222
+ subject { object.register(name, other, failure_chain, &chain_block) }
223
+
224
+ let(:chain) { chain_dsl.build(name, other, failure_chain, &chain_block) }
225
+
226
+ it_behaves_like 'Environment#register'
227
+ end
228
+ end
229
+
230
+ describe '.build' do
231
+
232
+ let(:expected) { described_class.new(app_env, actions, chain_dsl) }
233
+ let(:chain_dsl) { Chain::DSL.build(described_class::DSL.registry(&block)) }
234
+ let(:block) { ->(_) { register(:test, Substation) } }
235
+
236
+ shared_examples 'Environment.build' do
237
+ it { should eql(expected) }
238
+
239
+ its(:app_env) { should be(app_env) }
240
+ end
241
+
242
+ context 'when no actions are given' do
243
+ subject { described_class.build(app_env, &block) }
244
+
245
+
246
+ it_behaves_like 'Environment.build'
247
+
248
+ its(:actions) { should eql(actions) }
249
+ end
250
+
251
+ context 'when actions are given' do
252
+ subject { described_class.build(app_env, actions, &block) }
253
+
254
+ it_behaves_like 'Environment.build'
255
+
256
+ its(:actions) { should be(actions) }
257
+ end
258
+ end
259
+ end
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Processor::Builder, '#call' do
6
+ subject { object.call(handler, failure_chain, observers) }
7
+
8
+ include_context 'Processor::Config#initialize'
9
+
10
+ let(:object) { described_class.new(name, klass, executor) }
11
+ let(:handler) { double('handler') }
12
+ let(:name) { double('name') }
13
+ let(:klass) { double('klass') }
14
+ let(:processor) { double('processor') }
15
+
16
+ before do
17
+ expect(klass).to receive(:new).with(name, handler, processor_config).and_return(processor)
18
+ end
19
+
20
+ it { should eql(processor) }
21
+ end
@@ -0,0 +1,40 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Processor::Config do
6
+ describe '#executor' do
7
+ subject { processor_config.executor }
8
+
9
+ include_context 'Processor::Config#initialize'
10
+
11
+ it { should be(executor) }
12
+ end
13
+
14
+ describe '#failure_chain' do
15
+ subject { processor_config.failure_chain }
16
+
17
+ include_context 'Processor::Config#initialize'
18
+
19
+ it { should be(failure_chain) }
20
+ end
21
+
22
+ describe '#observers' do
23
+ subject { processor_config.observers }
24
+
25
+ include_context 'Processor::Config#initialize'
26
+
27
+ it { should be(observers) }
28
+ end
29
+
30
+ describe '#with_failure_chain' do
31
+ subject { processor_config.with_failure_chain(other_failure_chain) }
32
+
33
+ let(:other_failure_chain) { double('other failure chain') }
34
+ let(:object) { described_class.new(executor, other_failure_chain, observers) }
35
+
36
+ include_context 'Processor::Config#initialize'
37
+
38
+ it { should eql(object) }
39
+ end
40
+ end