substation 0.0.9 → 0.0.10.beta2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.travis.yml +0 -1
- data/Changelog.md +24 -82
- data/Gemfile.devtools +17 -24
- data/README.md +46 -116
- data/config/flay.yml +2 -2
- data/config/flog.yml +1 -1
- data/config/mutant.yml +0 -1
- data/config/reek.yml +5 -10
- data/lib/substation.rb +3 -8
- data/lib/substation/chain.rb +64 -108
- data/lib/substation/chain/dsl.rb +30 -57
- data/lib/substation/dispatcher.rb +1 -3
- data/lib/substation/environment.rb +23 -9
- data/lib/substation/environment/dsl.rb +3 -4
- data/lib/substation/observer.rb +2 -4
- data/lib/substation/processor.rb +7 -106
- data/lib/substation/processor/evaluator.rb +42 -83
- data/lib/substation/processor/pivot.rb +25 -0
- data/lib/substation/processor/wrapper.rb +2 -4
- data/lib/substation/request.rb +1 -10
- data/lib/substation/response.rb +0 -11
- data/lib/substation/utils.rb +1 -3
- data/lib/substation/version.rb +1 -3
- data/spec/integration/substation/dispatcher/call_spec.rb +12 -12
- data/spec/spec_helper.rb +21 -30
- data/spec/unit/substation/chain/call_spec.rb +32 -202
- data/spec/unit/substation/chain/dsl/builder/class_methods/call_spec.rb +2 -2
- data/spec/unit/substation/chain/dsl/builder/dsl_spec.rb +6 -8
- data/spec/unit/substation/chain/dsl/builder/failure_chain_spec.rb +30 -0
- data/spec/unit/substation/chain/dsl/chain_spec.rb +2 -1
- data/spec/unit/substation/chain/dsl/class_methods/processors_spec.rb +24 -0
- data/spec/unit/substation/chain/dsl/initialize_spec.rb +19 -0
- data/spec/unit/substation/chain/dsl/processors_spec.rb +21 -9
- data/spec/unit/substation/chain/dsl/use_spec.rb +3 -2
- data/spec/unit/substation/chain/each_spec.rb +9 -5
- data/spec/unit/substation/chain/incoming/result_spec.rb +21 -0
- data/spec/unit/substation/chain/outgoing/call_spec.rb +25 -0
- data/spec/unit/substation/{processor → chain/outgoing}/result_spec.rb +5 -6
- data/spec/unit/substation/dispatcher/action/call_spec.rb +6 -7
- data/spec/unit/substation/dispatcher/action/class_methods/coerce_spec.rb +5 -7
- data/spec/unit/substation/dispatcher/action_names_spec.rb +1 -1
- data/spec/unit/substation/dispatcher/call_spec.rb +3 -3
- data/spec/unit/substation/dispatcher/class_methods/coerce_spec.rb +7 -7
- data/spec/unit/substation/environment/chain_spec.rb +32 -22
- data/spec/unit/substation/environment/class_methods/build_spec.rb +4 -11
- data/spec/unit/substation/environment/dsl/class_methods/registry_spec.rb +3 -5
- data/spec/unit/substation/environment/dsl/register_spec.rb +3 -8
- data/spec/unit/substation/environment/dsl/registry_spec.rb +3 -5
- data/spec/unit/substation/observer/chain/call_spec.rb +3 -5
- data/spec/unit/substation/observer/class_methods/coerce_spec.rb +2 -4
- data/spec/unit/substation/observer/null/call_spec.rb +1 -3
- data/spec/unit/substation/processor/evaluator/call_spec.rb +35 -21
- data/spec/unit/substation/processor/pivot/call_spec.rb +17 -0
- data/spec/unit/substation/processor/wrapper/call_spec.rb +7 -8
- data/spec/unit/substation/request/env_spec.rb +4 -5
- data/spec/unit/substation/request/error_spec.rb +4 -5
- data/spec/unit/substation/request/input_spec.rb +4 -5
- data/spec/unit/substation/request/success_spec.rb +4 -5
- data/spec/unit/substation/response/env_spec.rb +5 -6
- data/spec/unit/substation/response/failure/success_predicate_spec.rb +4 -5
- data/spec/unit/substation/response/input_spec.rb +5 -6
- data/spec/unit/substation/response/output_spec.rb +4 -5
- data/spec/unit/substation/response/request_spec.rb +5 -6
- data/spec/unit/substation/response/success/success_predicate_spec.rb +4 -5
- data/spec/unit/substation/utils/class_methods/coerce_callable_spec.rb +13 -15
- data/spec/unit/substation/utils/class_methods/const_get_spec.rb +6 -6
- data/spec/unit/substation/utils/class_methods/symbolize_keys_spec.rb +4 -4
- data/substation.gemspec +1 -1
- metadata +18 -45
- data/config/rubocop.yml +0 -35
- data/lib/substation/processor/transformer.rb +0 -26
- data/spec/unit/substation/chain/class_methods/failure_response_spec.rb +0 -16
- data/spec/unit/substation/chain/dsl/class_methods/build_spec.rb +0 -24
- data/spec/unit/substation/chain/dsl/failure_chain_spec.rb +0 -35
- data/spec/unit/substation/chain/failure_data/equalizer_spec.rb +0 -46
- data/spec/unit/substation/chain/failure_data/hash_spec.rb +0 -13
- data/spec/unit/substation/environment/equalizer_spec.rb +0 -25
- data/spec/unit/substation/processor/evaluator/class_methods/new_spec.rb +0 -9
- data/spec/unit/substation/processor/evaluator/data/call_spec.rb +0 -34
- data/spec/unit/substation/processor/evaluator/pivot/call_spec.rb +0 -34
- data/spec/unit/substation/processor/evaluator/request/call_spec.rb +0 -34
- data/spec/unit/substation/processor/fallible/name_spec.rb +0 -15
- data/spec/unit/substation/processor/fallible/with_failure_chain_spec.rb +0 -18
- data/spec/unit/substation/processor/incoming/result_spec.rb +0 -25
- data/spec/unit/substation/processor/outgoing/call_spec.rb +0 -28
- data/spec/unit/substation/processor/outgoing/name_spec.rb +0 -14
- data/spec/unit/substation/processor/outgoing/success_predicate_spec.rb +0 -15
- data/spec/unit/substation/processor/success_predicate_spec.rb +0 -22
- data/spec/unit/substation/processor/transformer/call_spec.rb +0 -21
- data/spec/unit/substation/request/name_spec.rb +0 -15
- data/spec/unit/substation/response/to_request_spec.rb +0 -19
@@ -1,13 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Chain::FailureData, '#hash' do
|
6
|
-
subject { object.hash }
|
7
|
-
|
8
|
-
let(:object) { described_class.new(data, exception) }
|
9
|
-
let(:data) { mock }
|
10
|
-
let(:exception) { mock }
|
11
|
-
|
12
|
-
it { should eql(described_class.hash ^ data.hash ^ exception.class.hash) }
|
13
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Substation::Environment, 'equalizer behavior' do
|
6
|
-
subject { object == other }
|
7
|
-
|
8
|
-
let(:object) { described_class.new(registry, dsl) }
|
9
|
-
let(:other) { described_class.new(other_registry, dsl) }
|
10
|
-
|
11
|
-
let(:registry) { mock }
|
12
|
-
let(:dsl) { mock }
|
13
|
-
|
14
|
-
context 'with an equal registry' do
|
15
|
-
let(:other_registry) { registry }
|
16
|
-
|
17
|
-
it { should be(true) }
|
18
|
-
end
|
19
|
-
|
20
|
-
context 'with a different registry' do
|
21
|
-
let(:other_registry) { mock }
|
22
|
-
|
23
|
-
it { should be(false) }
|
24
|
-
end
|
25
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Processor::Evaluator::Data, '#call' do
|
6
|
-
subject { object.call(request) }
|
7
|
-
|
8
|
-
let(:object) { described_class.new(processor_name, handler, failure_chain) }
|
9
|
-
let(:processor_name) { mock }
|
10
|
-
let(:failure_chain) { mock(:call => failure_response) }
|
11
|
-
let(:failure_response) { mock }
|
12
|
-
let(:handler) { Spec::Handler::Evaluator }
|
13
|
-
let(:request) { Request.new(action_name, env, input) }
|
14
|
-
let(:action_name) { mock }
|
15
|
-
let(:env) { mock }
|
16
|
-
|
17
|
-
context 'with a successful handler' do
|
18
|
-
let(:input) { :success }
|
19
|
-
let(:response) { request.success(input) }
|
20
|
-
|
21
|
-
it { should eql(response) }
|
22
|
-
end
|
23
|
-
|
24
|
-
context 'with a failing handler' do
|
25
|
-
let(:input) { :foo }
|
26
|
-
let(:response) { request.error(:failure) }
|
27
|
-
|
28
|
-
before do
|
29
|
-
failure_chain.should_receive(:call).with(response).and_return(failure_response)
|
30
|
-
end
|
31
|
-
|
32
|
-
it { should eql(failure_response) }
|
33
|
-
end
|
34
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Processor::Evaluator::Pivot, '#call' do
|
6
|
-
subject { object.call(request) }
|
7
|
-
|
8
|
-
let(:object) { described_class.new(processor_name, handler, failure_chain) }
|
9
|
-
let(:processor_name) { mock }
|
10
|
-
let(:failure_chain) { mock(:call => failure_response) }
|
11
|
-
let(:failure_response) { mock }
|
12
|
-
let(:request) { Request.new(action_name, env, input) }
|
13
|
-
let(:action_name) { mock }
|
14
|
-
let(:env) { mock }
|
15
|
-
let(:input) { mock }
|
16
|
-
|
17
|
-
context 'with a successful handler' do
|
18
|
-
let(:handler) { Spec::Action::Success }
|
19
|
-
let(:response) { Response::Success.new(request, Spec.response_data) }
|
20
|
-
|
21
|
-
it { should eql(response) }
|
22
|
-
end
|
23
|
-
|
24
|
-
context 'with a failing handler' do
|
25
|
-
let(:handler) { Spec::Action::Failure }
|
26
|
-
let(:response) { Response::Failure.new(request, Spec.response_data) }
|
27
|
-
|
28
|
-
before do
|
29
|
-
failure_chain.should_receive(:call).with(response).and_return(failure_response)
|
30
|
-
end
|
31
|
-
|
32
|
-
it { should eql(failure_response) }
|
33
|
-
end
|
34
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Processor::Evaluator::Request, '#call' do
|
6
|
-
subject { object.call(request) }
|
7
|
-
|
8
|
-
let(:object) { described_class.new(processor_name, handler, failure_chain) }
|
9
|
-
let(:processor_name) { mock }
|
10
|
-
let(:failure_chain) { mock(:call => failure_response) }
|
11
|
-
let(:failure_response) { mock }
|
12
|
-
let(:request) { Request.new(action_name, env, input) }
|
13
|
-
let(:action_name) { mock }
|
14
|
-
let(:env) { mock }
|
15
|
-
let(:input) { mock }
|
16
|
-
|
17
|
-
context 'with a successful handler' do
|
18
|
-
let(:handler) { Spec::Action::Success }
|
19
|
-
let(:response) { Response::Success.new(request, Spec.response_data) }
|
20
|
-
|
21
|
-
it { should eql(response) }
|
22
|
-
end
|
23
|
-
|
24
|
-
context 'with a failing handler' do
|
25
|
-
let(:handler) { Spec::Action::Failure }
|
26
|
-
let(:response) { Response::Failure.new(request, Spec.response_data) }
|
27
|
-
|
28
|
-
before do
|
29
|
-
failure_chain.should_receive(:call).with(response).and_return(failure_response)
|
30
|
-
end
|
31
|
-
|
32
|
-
it { should eql(failure_response) }
|
33
|
-
end
|
34
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Processor::Fallible, '#name' do
|
6
|
-
subject { object.name }
|
7
|
-
|
8
|
-
let(:object) { klass.new(name, handler, failure_chain) }
|
9
|
-
let(:klass) { Class.new { include Processor::Fallible } }
|
10
|
-
let(:name) { mock }
|
11
|
-
let(:handler) { mock }
|
12
|
-
let(:failure_chain) { mock }
|
13
|
-
|
14
|
-
it { should be(name) }
|
15
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Processor::Fallible, '#with_failure_chain' do
|
6
|
-
subject { object.with_failure_chain(chain) }
|
7
|
-
|
8
|
-
let(:object) { klass.new(name, handler, failure_chain) }
|
9
|
-
let(:klass) { Class.new { include Processor::Fallible } }
|
10
|
-
let(:name) { mock }
|
11
|
-
let(:handler) { mock }
|
12
|
-
let(:failure_chain) { mock }
|
13
|
-
let(:chain) { mock }
|
14
|
-
|
15
|
-
let(:expected) { klass.new(name, handler, chain) }
|
16
|
-
|
17
|
-
it { should eql(expected) }
|
18
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Processor::Incoming, '#result' do
|
6
|
-
|
7
|
-
subject { object.result(response) }
|
8
|
-
|
9
|
-
let(:object) {
|
10
|
-
Class.new {
|
11
|
-
include Substation::Processor::Incoming
|
12
|
-
}.new(processor_name, handler, failure_chain)
|
13
|
-
}
|
14
|
-
|
15
|
-
let(:processor_name) { mock }
|
16
|
-
let(:response) { Response::Success.new(request, input) }
|
17
|
-
let(:request) { Request.new(action_name, env, input) }
|
18
|
-
let(:action_name) { mock }
|
19
|
-
let(:env) { mock }
|
20
|
-
let(:input) { mock }
|
21
|
-
let(:failure_chain) { mock }
|
22
|
-
let(:handler) { mock }
|
23
|
-
|
24
|
-
it { should eql(request) }
|
25
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Processor::Outgoing, '#call' do
|
6
|
-
|
7
|
-
subject { object.call(request) }
|
8
|
-
|
9
|
-
let(:object) {
|
10
|
-
Class.new {
|
11
|
-
include Substation::Processor::Outgoing
|
12
|
-
def call(request)
|
13
|
-
response = request.success(request.input)
|
14
|
-
respond_with(response, :altered)
|
15
|
-
end
|
16
|
-
}.new(processor_name, handler)
|
17
|
-
}
|
18
|
-
|
19
|
-
let(:processor_name) { mock }
|
20
|
-
let(:response) { Response::Success.new(request, :altered) }
|
21
|
-
let(:request) { Request.new(action_name, env, input) }
|
22
|
-
let(:action_name) { mock }
|
23
|
-
let(:env) { mock }
|
24
|
-
let(:input) { mock }
|
25
|
-
let(:handler) { mock }
|
26
|
-
|
27
|
-
it { should eql(response) }
|
28
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Processor::Outgoing, '#name' do
|
6
|
-
subject { object.name }
|
7
|
-
|
8
|
-
let(:object) { klass.new(name, handler) }
|
9
|
-
let(:klass) { Class.new { include Processor::Outgoing } }
|
10
|
-
let(:name) { mock }
|
11
|
-
let(:handler) { mock }
|
12
|
-
|
13
|
-
it { should be(name) }
|
14
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Processor::Outgoing, '#success?' do
|
6
|
-
subject { object.success?(response) }
|
7
|
-
|
8
|
-
let(:object) { klass.new(name, handler) }
|
9
|
-
let(:klass) { Class.new { include Processor::Outgoing } }
|
10
|
-
let(:name) { mock }
|
11
|
-
let(:handler) { mock }
|
12
|
-
let(:response) { mock }
|
13
|
-
|
14
|
-
it { should be(true) }
|
15
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Processor, '#success?' do
|
6
|
-
subject { object.success?(response) }
|
7
|
-
|
8
|
-
let(:object) { klass.new }
|
9
|
-
let(:klass) { Class.new { include Processor } }
|
10
|
-
|
11
|
-
context 'with a successful response' do
|
12
|
-
let(:response) { mock(:success? => true) }
|
13
|
-
|
14
|
-
it { should be(true) }
|
15
|
-
end
|
16
|
-
|
17
|
-
context 'with a failure response' do
|
18
|
-
let(:response) { mock(:success? => false) }
|
19
|
-
|
20
|
-
it { should be(false) }
|
21
|
-
end
|
22
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Processor::Transformer, '#call' do
|
6
|
-
subject { object.call(response) }
|
7
|
-
|
8
|
-
let(:object) { described_class.new(processor_name, Spec::Transformer) }
|
9
|
-
let(:processor_name) { mock }
|
10
|
-
let(:response) { Response::Success.new(request, output) }
|
11
|
-
let(:request) { Request.new(action_name, env, input) }
|
12
|
-
let(:action_name) { mock }
|
13
|
-
let(:env) { mock }
|
14
|
-
let(:input) { mock }
|
15
|
-
let(:output) { mock }
|
16
|
-
|
17
|
-
let(:transformed) { Response::Success.new(request, data) }
|
18
|
-
let(:data) { Spec::Transformer.call(response) }
|
19
|
-
|
20
|
-
it { should eql(transformed) }
|
21
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Request, '#name' do
|
6
|
-
|
7
|
-
subject { object.name }
|
8
|
-
|
9
|
-
let(:object) { described_class.new(name, env, input) }
|
10
|
-
let(:name) { mock }
|
11
|
-
let(:env) { mock }
|
12
|
-
let(:input) { mock }
|
13
|
-
|
14
|
-
it { should be(name) }
|
15
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Response, '#to_request' do
|
6
|
-
|
7
|
-
subject { object.to_request }
|
8
|
-
|
9
|
-
let(:object) { Class.new(described_class).new(request, output) }
|
10
|
-
let(:request) { Request.new(name, env, input) }
|
11
|
-
let(:name) { mock }
|
12
|
-
let(:env) { mock }
|
13
|
-
let(:input) { mock }
|
14
|
-
let(:output) { mock }
|
15
|
-
|
16
|
-
let(:response) { Request.new(name, env, output) }
|
17
|
-
|
18
|
-
it { should eql(response) }
|
19
|
-
end
|