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.
Files changed (92) hide show
  1. checksums.yaml +7 -0
  2. data/.travis.yml +0 -1
  3. data/Changelog.md +24 -82
  4. data/Gemfile.devtools +17 -24
  5. data/README.md +46 -116
  6. data/config/flay.yml +2 -2
  7. data/config/flog.yml +1 -1
  8. data/config/mutant.yml +0 -1
  9. data/config/reek.yml +5 -10
  10. data/lib/substation.rb +3 -8
  11. data/lib/substation/chain.rb +64 -108
  12. data/lib/substation/chain/dsl.rb +30 -57
  13. data/lib/substation/dispatcher.rb +1 -3
  14. data/lib/substation/environment.rb +23 -9
  15. data/lib/substation/environment/dsl.rb +3 -4
  16. data/lib/substation/observer.rb +2 -4
  17. data/lib/substation/processor.rb +7 -106
  18. data/lib/substation/processor/evaluator.rb +42 -83
  19. data/lib/substation/processor/pivot.rb +25 -0
  20. data/lib/substation/processor/wrapper.rb +2 -4
  21. data/lib/substation/request.rb +1 -10
  22. data/lib/substation/response.rb +0 -11
  23. data/lib/substation/utils.rb +1 -3
  24. data/lib/substation/version.rb +1 -3
  25. data/spec/integration/substation/dispatcher/call_spec.rb +12 -12
  26. data/spec/spec_helper.rb +21 -30
  27. data/spec/unit/substation/chain/call_spec.rb +32 -202
  28. data/spec/unit/substation/chain/dsl/builder/class_methods/call_spec.rb +2 -2
  29. data/spec/unit/substation/chain/dsl/builder/dsl_spec.rb +6 -8
  30. data/spec/unit/substation/chain/dsl/builder/failure_chain_spec.rb +30 -0
  31. data/spec/unit/substation/chain/dsl/chain_spec.rb +2 -1
  32. data/spec/unit/substation/chain/dsl/class_methods/processors_spec.rb +24 -0
  33. data/spec/unit/substation/chain/dsl/initialize_spec.rb +19 -0
  34. data/spec/unit/substation/chain/dsl/processors_spec.rb +21 -9
  35. data/spec/unit/substation/chain/dsl/use_spec.rb +3 -2
  36. data/spec/unit/substation/chain/each_spec.rb +9 -5
  37. data/spec/unit/substation/chain/incoming/result_spec.rb +21 -0
  38. data/spec/unit/substation/chain/outgoing/call_spec.rb +25 -0
  39. data/spec/unit/substation/{processor → chain/outgoing}/result_spec.rb +5 -6
  40. data/spec/unit/substation/dispatcher/action/call_spec.rb +6 -7
  41. data/spec/unit/substation/dispatcher/action/class_methods/coerce_spec.rb +5 -7
  42. data/spec/unit/substation/dispatcher/action_names_spec.rb +1 -1
  43. data/spec/unit/substation/dispatcher/call_spec.rb +3 -3
  44. data/spec/unit/substation/dispatcher/class_methods/coerce_spec.rb +7 -7
  45. data/spec/unit/substation/environment/chain_spec.rb +32 -22
  46. data/spec/unit/substation/environment/class_methods/build_spec.rb +4 -11
  47. data/spec/unit/substation/environment/dsl/class_methods/registry_spec.rb +3 -5
  48. data/spec/unit/substation/environment/dsl/register_spec.rb +3 -8
  49. data/spec/unit/substation/environment/dsl/registry_spec.rb +3 -5
  50. data/spec/unit/substation/observer/chain/call_spec.rb +3 -5
  51. data/spec/unit/substation/observer/class_methods/coerce_spec.rb +2 -4
  52. data/spec/unit/substation/observer/null/call_spec.rb +1 -3
  53. data/spec/unit/substation/processor/evaluator/call_spec.rb +35 -21
  54. data/spec/unit/substation/processor/pivot/call_spec.rb +17 -0
  55. data/spec/unit/substation/processor/wrapper/call_spec.rb +7 -8
  56. data/spec/unit/substation/request/env_spec.rb +4 -5
  57. data/spec/unit/substation/request/error_spec.rb +4 -5
  58. data/spec/unit/substation/request/input_spec.rb +4 -5
  59. data/spec/unit/substation/request/success_spec.rb +4 -5
  60. data/spec/unit/substation/response/env_spec.rb +5 -6
  61. data/spec/unit/substation/response/failure/success_predicate_spec.rb +4 -5
  62. data/spec/unit/substation/response/input_spec.rb +5 -6
  63. data/spec/unit/substation/response/output_spec.rb +4 -5
  64. data/spec/unit/substation/response/request_spec.rb +5 -6
  65. data/spec/unit/substation/response/success/success_predicate_spec.rb +4 -5
  66. data/spec/unit/substation/utils/class_methods/coerce_callable_spec.rb +13 -15
  67. data/spec/unit/substation/utils/class_methods/const_get_spec.rb +6 -6
  68. data/spec/unit/substation/utils/class_methods/symbolize_keys_spec.rb +4 -4
  69. data/substation.gemspec +1 -1
  70. metadata +18 -45
  71. data/config/rubocop.yml +0 -35
  72. data/lib/substation/processor/transformer.rb +0 -26
  73. data/spec/unit/substation/chain/class_methods/failure_response_spec.rb +0 -16
  74. data/spec/unit/substation/chain/dsl/class_methods/build_spec.rb +0 -24
  75. data/spec/unit/substation/chain/dsl/failure_chain_spec.rb +0 -35
  76. data/spec/unit/substation/chain/failure_data/equalizer_spec.rb +0 -46
  77. data/spec/unit/substation/chain/failure_data/hash_spec.rb +0 -13
  78. data/spec/unit/substation/environment/equalizer_spec.rb +0 -25
  79. data/spec/unit/substation/processor/evaluator/class_methods/new_spec.rb +0 -9
  80. data/spec/unit/substation/processor/evaluator/data/call_spec.rb +0 -34
  81. data/spec/unit/substation/processor/evaluator/pivot/call_spec.rb +0 -34
  82. data/spec/unit/substation/processor/evaluator/request/call_spec.rb +0 -34
  83. data/spec/unit/substation/processor/fallible/name_spec.rb +0 -15
  84. data/spec/unit/substation/processor/fallible/with_failure_chain_spec.rb +0 -18
  85. data/spec/unit/substation/processor/incoming/result_spec.rb +0 -25
  86. data/spec/unit/substation/processor/outgoing/call_spec.rb +0 -28
  87. data/spec/unit/substation/processor/outgoing/name_spec.rb +0 -14
  88. data/spec/unit/substation/processor/outgoing/success_predicate_spec.rb +0 -15
  89. data/spec/unit/substation/processor/success_predicate_spec.rb +0 -22
  90. data/spec/unit/substation/processor/transformer/call_spec.rb +0 -21
  91. data/spec/unit/substation/request/name_spec.rb +0 -15
  92. 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(:expected) { Environment.new(registry, chain_dsl) }
9
- let(:chain_dsl) { Chain::DSL::Builder.call(registry) }
10
- let(:registry) { described_class::DSL.new(&block).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 'when a block is given' do
4
+ context "when a block is given" do
7
5
  subject { described_class.registry(&block) }
8
6
 
9
- let(:block) { ->(_) { register :test, Spec::Processor } }
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 'when no block is given' do
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
- it_behaves_like 'a command method'
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 'when a block is given' do
6
+ context "when a block is given" do
9
7
  let(:object) { described_class.new(&block) }
10
- let(:block) { ->(_) { register :test, Spec::Processor } }
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 'when no block is given' do
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) { mock('Response') }
11
- let(:observer_a) { mock('Observer A') }
12
- let(:observer_b) { mock('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) { mock }
27
- let(:coerced) { mock }
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)
@@ -1,12 +1,10 @@
1
- # encoding: utf-8
2
-
3
1
  require 'spec_helper'
4
2
 
5
3
  describe Observer::NULL, '#call' do
6
4
  subject { object.call(input) }
7
5
 
8
6
  let(:object) { described_class }
9
- let(:input) { mock }
7
+ let(:input) { double }
10
8
 
11
9
  it_should_behave_like 'a command method'
12
10
 
@@ -5,31 +5,45 @@ require 'spec_helper'
5
5
  describe Processor::Evaluator, '#call' do
6
6
  subject { object.call(request) }
7
7
 
8
- let(:object) { klass.new(processor_name, handler, failure_chain) }
9
- let(:processor_name) { mock }
10
- let(:klass) { Class.new(described_class) { include Processor::Incoming } }
11
- let(:failure_chain) { mock(:call => failure_response) }
12
- let(:failure_response) { mock }
13
- let(:request) { Request.new(action_name, env, input) }
14
- let(:action_name) { mock }
15
- let(:env) { mock }
16
- let(:input) { mock }
17
-
18
- context 'with a successful handler' do
19
- let(:handler) { Spec::Action::Success }
20
- let(:response) { Response::Success.new(request, Spec.response_data) }
21
-
22
- it { should eql(response) }
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 'with a failing handler' do
26
- let(:handler) { Spec::Action::Failure }
27
- let(:response) { Response::Failure.new(request, Spec.response_data) }
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
- before do
30
- failure_chain.should_receive(:call).with(response).and_return(failure_response)
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
- it { should eql(failure_response) }
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) { described_class.new(processor_name, Spec::Presenter) }
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 }
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(name, env, input) }
10
- let(:name) { mock }
11
- let(:env) { mock }
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 be(env) }
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(name, env, input) }
10
- let(:name) { mock }
11
- let(:env) { mock }
12
- let(:input) { mock }
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(name, env, input) }
10
- let(:name) { mock }
11
- let(:env) { mock }
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 be(input) }
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(name, env, input) }
10
- let(:name) { mock }
11
- let(:env) { mock }
12
- let(:input) { mock }
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(name, env, input) }
11
- let(:name) { mock }
12
- let(:env) { mock }
13
- let(:input) { mock }
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 be(env) }
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(name, env, input) }
10
- let(:name) { mock }
11
- let(:env) { mock }
12
- let(:input) { mock }
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(name, env, input) }
11
- let(:name) { mock }
12
- let(:env) { mock }
13
- let(:input) { mock }
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 be(input) }
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(name, env, input) }
11
- let(:name) { mock }
12
- let(:env) { mock }
13
- let(:input) { mock }
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(name, env, input) }
11
- let(:name) { mock }
12
- let(:env) { mock }
13
- let(:input) { mock }
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 be(request) }
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(name, env, input) }
10
- let(:name) { mock }
11
- let(:env) { mock }
12
- let(:input) { mock }
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
- let(:const) { Spec::Action::Success }
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 'with a Symbol handler' do
18
- let(:handler) { const.name.to_sym }
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 'with a const handler' do
24
- let(:handler) { const }
21
+ context "with a const handler" do
22
+ let(:handler) { Spec::Action::Success }
25
23
 
26
- it { should be(const) }
24
+ it { should be(Spec::Action::Success) }
27
25
  end
28
26
 
29
- context 'with a Proc handler' do
30
- let(:handler) { ->(response) { response } }
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 'with a Chain handler' do
36
- let(:handler) { Chain.new(EMPTY_ARRAY, Chain::EMPTY) }
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 'with an unsupported handler' do
42
- let(:handler) { mock }
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)