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,18 +1,11 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
1
|
require 'spec_helper'
|
4
2
|
|
5
|
-
describe Environment, '.build' do
|
3
|
+
describe Substation::Environment, '.build' do
|
6
4
|
subject { described_class.build(&block) }
|
7
5
|
|
8
|
-
let(:
|
9
|
-
let(:
|
10
|
-
let(:registry)
|
11
|
-
let(:block) { ->(_) { register(:test, Substation) } }
|
6
|
+
let(:block) { lambda { |_| register(:test, Substation) } }
|
7
|
+
let(:expected) { described_class.new(registry) }
|
8
|
+
let(:registry) { described_class::DSL.registry(&block) }
|
12
9
|
|
13
10
|
it { should eql(expected) }
|
14
|
-
|
15
|
-
it 'uses the compiled dsl' do
|
16
|
-
expect(subject.chain).to eql(chain_dsl.build(Chain::EMPTY, Chain::EMPTY))
|
17
|
-
end
|
18
11
|
end
|
@@ -1,18 +1,16 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
1
|
require 'spec_helper'
|
4
2
|
|
5
3
|
describe Substation::Environment::DSL, '.registry' do
|
6
|
-
context
|
4
|
+
context "when a block is given" do
|
7
5
|
subject { described_class.registry(&block) }
|
8
6
|
|
9
|
-
let(:block) {
|
7
|
+
let(:block) { lambda { |_| register :test, Spec::Processor } }
|
10
8
|
let(:expected) { { :test => Spec::Processor } }
|
11
9
|
|
12
10
|
it { should eql(expected) }
|
13
11
|
end
|
14
12
|
|
15
|
-
context
|
13
|
+
context "when no block is given" do
|
16
14
|
subject { described_class.registry }
|
17
15
|
|
18
16
|
it { should eql({}) }
|
@@ -1,8 +1,6 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
1
|
require 'spec_helper'
|
4
2
|
|
5
|
-
describe Environment::DSL, '#register' do
|
3
|
+
describe Substation::Environment::DSL, '#register' do
|
6
4
|
subject { object.register(name, processor) }
|
7
5
|
|
8
6
|
let(:object) { described_class.new }
|
@@ -10,10 +8,7 @@ describe Environment::DSL, '#register' do
|
|
10
8
|
let(:processor) { Spec::Processor }
|
11
9
|
|
12
10
|
let(:expected) { { :test => Spec::Processor } }
|
11
|
+
let(:block) { lambda { |_| register :test, Spec::Processor } }
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
it 'registers the given processor' do
|
17
|
-
expect(subject.registry).to eql(expected)
|
18
|
-
end
|
13
|
+
its(:registry) { should eql(expected) }
|
19
14
|
end
|
@@ -1,19 +1,17 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
1
|
require 'spec_helper'
|
4
2
|
|
5
3
|
describe Substation::Environment::DSL, '#registry' do
|
6
4
|
subject { object.registry }
|
7
5
|
|
8
|
-
context
|
6
|
+
context "when a block is given" do
|
9
7
|
let(:object) { described_class.new(&block) }
|
10
|
-
let(:block) {
|
8
|
+
let(:block) { lambda { |_| register :test, Spec::Processor } }
|
11
9
|
let(:expected) { { :test => Spec::Processor } }
|
12
10
|
|
13
11
|
it { should eql(expected) }
|
14
12
|
end
|
15
13
|
|
16
|
-
context
|
14
|
+
context "when no block is given" do
|
17
15
|
let(:object) { described_class.new }
|
18
16
|
|
19
17
|
it { should eql({}) }
|
@@ -1,5 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
1
|
require 'spec_helper'
|
4
2
|
|
5
3
|
describe Observer::Chain, '#call' do
|
@@ -7,9 +5,9 @@ describe Observer::Chain, '#call' do
|
|
7
5
|
|
8
6
|
let(:object) { Observer::Chain.new(observers) }
|
9
7
|
|
10
|
-
let(:response) {
|
11
|
-
let(:observer_a) {
|
12
|
-
let(:observer_b) {
|
8
|
+
let(:response) { double('Response') }
|
9
|
+
let(:observer_a) { double('Observer A') }
|
10
|
+
let(:observer_b) { double('Observer B') }
|
13
11
|
|
14
12
|
let(:observers) { [observer_a, observer_b] }
|
15
13
|
|
@@ -1,5 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
1
|
require 'spec_helper'
|
4
2
|
|
5
3
|
describe Observer, '.coerce' do
|
@@ -23,8 +21,8 @@ describe Observer, '.coerce' do
|
|
23
21
|
end
|
24
22
|
|
25
23
|
context 'with other input' do
|
26
|
-
let(:input) {
|
27
|
-
let(:coerced) {
|
24
|
+
let(:input) { double }
|
25
|
+
let(:coerced) { double }
|
28
26
|
|
29
27
|
before do
|
30
28
|
Utils.should_receive(:coerce_callable).with(input).and_return(coerced)
|
@@ -5,31 +5,45 @@ require 'spec_helper'
|
|
5
5
|
describe Processor::Evaluator, '#call' do
|
6
6
|
subject { object.call(request) }
|
7
7
|
|
8
|
-
let(:
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
8
|
+
let(:request) { Request.new(double('env'), input) }
|
9
|
+
|
10
|
+
context "when no failure chain is registered" do
|
11
|
+
|
12
|
+
let(:object) { described_class.new(Spec::FAKE_ENV, Spec::Handler::Evaluator.new) }
|
13
|
+
|
14
|
+
context "when evaluation is successful" do
|
15
|
+
let(:input) { :success }
|
16
|
+
let(:response) { Response::Success.new(request, input) }
|
17
|
+
|
18
|
+
it { should eql(response) }
|
19
|
+
end
|
20
|
+
|
21
|
+
context "when evaluation is not successful" do
|
22
|
+
let(:input) { :invalid }
|
23
|
+
let(:response) { Response::Failure.new(request, :failure) }
|
24
|
+
|
25
|
+
it { should eql(response) }
|
26
|
+
end
|
23
27
|
end
|
24
28
|
|
25
|
-
context
|
26
|
-
|
27
|
-
let(:
|
29
|
+
context "when a failure chain is registered" do
|
30
|
+
|
31
|
+
let(:object) { described_class.new(env, Spec::Handler::Evaluator.new, &block) }
|
32
|
+
let(:env) { Environment.new({}) }
|
33
|
+
let(:block) { lambda { |_| use(Processor::Wrapper.new(env, Spec::Presenter)) } }
|
28
34
|
|
29
|
-
|
30
|
-
|
35
|
+
context "when evaluation is successful" do
|
36
|
+
let(:input) { :success }
|
37
|
+
let(:response) { Response::Success.new(request, input) }
|
38
|
+
|
39
|
+
it { should eql(response) }
|
31
40
|
end
|
32
41
|
|
33
|
-
|
42
|
+
context "when evaluation is not successful" do
|
43
|
+
let(:input) { :invalid }
|
44
|
+
let(:response) { Response::Failure.new(request, Spec::Presenter.new(:failure)) }
|
45
|
+
|
46
|
+
it { should eql(response) }
|
47
|
+
end
|
34
48
|
end
|
35
49
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Processor::Pivot, '#call' do
|
6
|
+
subject { object.call(request) }
|
7
|
+
|
8
|
+
let(:object) { described_class.new(s_env, Spec::Handler::Pivot.new) }
|
9
|
+
let(:s_env) { double }
|
10
|
+
let(:request) { Request.new(env, input) }
|
11
|
+
let(:env) { double }
|
12
|
+
let(:input) { double }
|
13
|
+
|
14
|
+
let(:response) { Response::Success.new(request, request.input) }
|
15
|
+
|
16
|
+
it { should eql(response) }
|
17
|
+
end
|
@@ -5,14 +5,13 @@ require 'spec_helper'
|
|
5
5
|
describe Processor::Wrapper, '#call' do
|
6
6
|
subject { object.call(response) }
|
7
7
|
|
8
|
-
let(:object)
|
9
|
-
let(:
|
10
|
-
let(:response)
|
11
|
-
let(:request)
|
12
|
-
let(:
|
13
|
-
let(:
|
14
|
-
let(:
|
15
|
-
let(:output) { mock }
|
8
|
+
let(:object) { described_class.new(s_env, Spec::Presenter) }
|
9
|
+
let(:s_env) { double }
|
10
|
+
let(:response) { Response::Success.new(request, output) }
|
11
|
+
let(:request) { Request.new(env, input) }
|
12
|
+
let(:env) { double }
|
13
|
+
let(:input) { double }
|
14
|
+
let(:output) { double }
|
16
15
|
|
17
16
|
let(:wrapped) { Response::Success.new(request, data) }
|
18
17
|
let(:data) { Spec::Presenter.new(output) }
|
@@ -6,10 +6,9 @@ describe Request, '#env' do
|
|
6
6
|
|
7
7
|
subject { object.env }
|
8
8
|
|
9
|
-
let(:object) { described_class.new(
|
10
|
-
let(:
|
11
|
-
let(:
|
12
|
-
let(:input) { mock }
|
9
|
+
let(:object) { described_class.new(env, input) }
|
10
|
+
let(:env) { double }
|
11
|
+
let(:input) { double }
|
13
12
|
|
14
|
-
it { should
|
13
|
+
it { should equal(env) }
|
15
14
|
end
|
@@ -6,11 +6,10 @@ describe Request, '#error' do
|
|
6
6
|
|
7
7
|
subject { object.error(output) }
|
8
8
|
|
9
|
-
let(:object) { described_class.new(
|
10
|
-
let(:
|
11
|
-
let(:
|
12
|
-
let(:
|
13
|
-
let(:output) { mock }
|
9
|
+
let(:object) { described_class.new(env, input) }
|
10
|
+
let(:env) { double }
|
11
|
+
let(:input) { double }
|
12
|
+
let(:output) { double }
|
14
13
|
|
15
14
|
it { should eql(Response::Failure.new(object, output)) }
|
16
15
|
end
|
@@ -6,10 +6,9 @@ describe Request, '#input' do
|
|
6
6
|
|
7
7
|
subject { object.input }
|
8
8
|
|
9
|
-
let(:object) { described_class.new(
|
10
|
-
let(:
|
11
|
-
let(:
|
12
|
-
let(:input) { mock }
|
9
|
+
let(:object) { described_class.new(env, input) }
|
10
|
+
let(:env) { double }
|
11
|
+
let(:input) { double }
|
13
12
|
|
14
|
-
it { should
|
13
|
+
it { should equal(input) }
|
15
14
|
end
|
@@ -6,11 +6,10 @@ describe Request, '#success' do
|
|
6
6
|
|
7
7
|
subject { object.success(output) }
|
8
8
|
|
9
|
-
let(:object) { described_class.new(
|
10
|
-
let(:
|
11
|
-
let(:
|
12
|
-
let(:
|
13
|
-
let(:output) { mock }
|
9
|
+
let(:object) { described_class.new(env, input) }
|
10
|
+
let(:env) { double }
|
11
|
+
let(:input) { double }
|
12
|
+
let(:output) { double }
|
14
13
|
|
15
14
|
it { should eql(Response::Success.new(object, output)) }
|
16
15
|
end
|
@@ -7,11 +7,10 @@ describe Response, '#env' do
|
|
7
7
|
subject { object.env }
|
8
8
|
|
9
9
|
let(:object) { Class.new(described_class).new(request, output) }
|
10
|
-
let(:request) { Request.new(
|
11
|
-
let(:
|
12
|
-
let(:
|
13
|
-
let(:
|
14
|
-
let(:output) { mock }
|
10
|
+
let(:request) { Request.new(env, input) }
|
11
|
+
let(:env) { double }
|
12
|
+
let(:input) { double }
|
13
|
+
let(:output) { double }
|
15
14
|
|
16
|
-
it { should
|
15
|
+
it { should equal(env) }
|
17
16
|
end
|
@@ -6,11 +6,10 @@ describe Response::Failure, '#success?' do
|
|
6
6
|
subject { object.success? }
|
7
7
|
|
8
8
|
let(:object) { described_class.new(request, output) }
|
9
|
-
let(:request) { Request.new(
|
10
|
-
let(:
|
11
|
-
let(:
|
12
|
-
let(:
|
13
|
-
let(:output) { mock }
|
9
|
+
let(:request) { Request.new(env, input) }
|
10
|
+
let(:env) { double }
|
11
|
+
let(:input) { double }
|
12
|
+
let(:output) { double }
|
14
13
|
|
15
14
|
it { should be(false) }
|
16
15
|
end
|
@@ -7,11 +7,10 @@ describe Response, '#input' do
|
|
7
7
|
subject { object.input }
|
8
8
|
|
9
9
|
let(:object) { Class.new(described_class).new(request, output) }
|
10
|
-
let(:request) { Request.new(
|
11
|
-
let(:
|
12
|
-
let(:
|
13
|
-
let(:
|
14
|
-
let(:output) { mock }
|
10
|
+
let(:request) { Request.new(env, input) }
|
11
|
+
let(:env) { double }
|
12
|
+
let(:input) { double }
|
13
|
+
let(:output) { double }
|
15
14
|
|
16
|
-
it { should
|
15
|
+
it { should equal(input) }
|
17
16
|
end
|
@@ -7,11 +7,10 @@ describe Response, '#output' do
|
|
7
7
|
subject { object.output }
|
8
8
|
|
9
9
|
let(:object) { Class.new(described_class).new(request, output) }
|
10
|
-
let(:request) { Request.new(
|
11
|
-
let(:
|
12
|
-
let(:
|
13
|
-
let(:
|
14
|
-
let(:output) { mock }
|
10
|
+
let(:request) { Request.new(env, input) }
|
11
|
+
let(:env) { double }
|
12
|
+
let(:input) { double }
|
13
|
+
let(:output) { double }
|
15
14
|
|
16
15
|
it { should equal(output) }
|
17
16
|
end
|
@@ -7,11 +7,10 @@ describe Response, '#request' do
|
|
7
7
|
subject { object.request }
|
8
8
|
|
9
9
|
let(:object) { Class.new(described_class).new(request, output) }
|
10
|
-
let(:request) { Request.new(
|
11
|
-
let(:
|
12
|
-
let(:
|
13
|
-
let(:
|
14
|
-
let(:output) { mock }
|
10
|
+
let(:request) { Request.new(env, input) }
|
11
|
+
let(:env) { double }
|
12
|
+
let(:input) { double }
|
13
|
+
let(:output) { double }
|
15
14
|
|
16
|
-
it { should
|
15
|
+
it { should equal(request) }
|
17
16
|
end
|
@@ -6,11 +6,10 @@ describe Response::Success, '#success?' do
|
|
6
6
|
subject { object.success? }
|
7
7
|
|
8
8
|
let(:object) { described_class.new(request, output) }
|
9
|
-
let(:request) { Request.new(
|
10
|
-
let(:
|
11
|
-
let(:
|
12
|
-
let(:
|
13
|
-
let(:output) { mock }
|
9
|
+
let(:request) { Request.new(env, input) }
|
10
|
+
let(:env) { double }
|
11
|
+
let(:input) { double }
|
12
|
+
let(:output) { double }
|
14
13
|
|
15
14
|
it { should be(true) }
|
16
15
|
end
|
@@ -6,40 +6,38 @@ describe Utils, '.coerce_callable' do
|
|
6
6
|
|
7
7
|
subject { described_class.coerce_callable(handler) }
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
context 'with a String handler' do
|
12
|
-
let(:handler) { const.name }
|
9
|
+
context "with a String handler" do
|
10
|
+
let(:handler) { 'Spec::Action::Success' }
|
13
11
|
|
14
12
|
it { should be(Spec::Action::Success) }
|
15
13
|
end
|
16
14
|
|
17
|
-
context
|
18
|
-
let(:handler) {
|
15
|
+
context "with a Symbol handler" do
|
16
|
+
let(:handler) { :'Spec::Action::Success' }
|
19
17
|
|
20
18
|
it { should be(Spec::Action::Success) }
|
21
19
|
end
|
22
20
|
|
23
|
-
context
|
24
|
-
let(:handler) {
|
21
|
+
context "with a const handler" do
|
22
|
+
let(:handler) { Spec::Action::Success }
|
25
23
|
|
26
|
-
it { should be(
|
24
|
+
it { should be(Spec::Action::Success) }
|
27
25
|
end
|
28
26
|
|
29
|
-
context
|
30
|
-
let(:handler) {
|
27
|
+
context "with a Proc handler" do
|
28
|
+
let(:handler) { Proc.new { |response| respone } }
|
31
29
|
|
32
30
|
it { should be(handler) }
|
33
31
|
end
|
34
32
|
|
35
|
-
context
|
36
|
-
let(:handler) { Chain.new(
|
33
|
+
context "with a Chain handler" do
|
34
|
+
let(:handler) { Chain.new([]) }
|
37
35
|
|
38
36
|
it { should be(handler) }
|
39
37
|
end
|
40
38
|
|
41
|
-
context
|
42
|
-
let(:handler) {
|
39
|
+
context "with an unsupported handler" do
|
40
|
+
let(:handler) { double }
|
43
41
|
|
44
42
|
specify do
|
45
43
|
expect { subject }.to raise_error(ArgumentError)
|