ducktrap 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.circle.yml +6 -0
- data/.gitignore +5 -0
- data/.rspec +1 -0
- data/.travis.yml +16 -0
- data/Gemfile +6 -0
- data/Gemfile.devtools +59 -0
- data/Guardfile +18 -0
- data/LICENSE +20 -0
- data/README.md +47 -0
- data/Rakefile +2 -0
- data/TODO +4 -0
- data/config/devtools.yml +2 -0
- data/config/flay.yml +3 -0
- data/config/flog.yml +2 -0
- data/config/heckle.yml +3 -0
- data/config/mutant.yml +2 -0
- data/config/reek.yml +98 -0
- data/config/yardstick.yml +2 -0
- data/ducktrap.gemspec +23 -0
- data/lib/ducktrap.rb +73 -0
- data/lib/ducktrap/builder.rb +36 -0
- data/lib/ducktrap/error.rb +48 -0
- data/lib/ducktrap/evaluator.rb +127 -0
- data/lib/ducktrap/evaluator/invalid.rb +30 -0
- data/lib/ducktrap/evaluator/static.rb +25 -0
- data/lib/ducktrap/formatter.rb +138 -0
- data/lib/ducktrap/mapper.rb +59 -0
- data/lib/ducktrap/nary.rb +148 -0
- data/lib/ducktrap/node.rb +94 -0
- data/lib/ducktrap/node/anima.rb +40 -0
- data/lib/ducktrap/node/anima/dump.rb +39 -0
- data/lib/ducktrap/node/anima/load.rb +39 -0
- data/lib/ducktrap/node/block.rb +44 -0
- data/lib/ducktrap/node/coercion.rb +7 -0
- data/lib/ducktrap/node/custom.rb +121 -0
- data/lib/ducktrap/node/disjunction.rb +8 -0
- data/lib/ducktrap/node/forward.rb +55 -0
- data/lib/ducktrap/node/guard_nil.rb +42 -0
- data/lib/ducktrap/node/hash.rb +7 -0
- data/lib/ducktrap/node/hash/transform.rb +53 -0
- data/lib/ducktrap/node/invalid.rb +29 -0
- data/lib/ducktrap/node/inverse.rb +46 -0
- data/lib/ducktrap/node/key.rb +61 -0
- data/lib/ducktrap/node/key/add.rb +42 -0
- data/lib/ducktrap/node/key/delete.rb +44 -0
- data/lib/ducktrap/node/key/dump.rb +38 -0
- data/lib/ducktrap/node/key/fetch.rb +49 -0
- data/lib/ducktrap/node/map.rb +42 -0
- data/lib/ducktrap/node/noop.rb +30 -0
- data/lib/ducktrap/node/primitive.rb +61 -0
- data/lib/ducktrap/node/static.rb +33 -0
- data/lib/ducktrap/nullary.rb +41 -0
- data/lib/ducktrap/pretty_dump.rb +31 -0
- data/lib/ducktrap/registry.rb +60 -0
- data/lib/ducktrap/singleton.rb +55 -0
- data/lib/ducktrap/unary.rb +153 -0
- data/spec/rcov.opts +7 -0
- data/spec/shared/inverse_behavior.rb +7 -0
- data/spec/spec_helper.rb +20 -0
- data/spec/support/ice_nine_config.rb +8 -0
- data/spec/support/let_mock_helper.rb +13 -0
- data/spec/unit/ducktrap/builder/class_methods/new_spec.rb +41 -0
- data/spec/unit/ducktrap/builder/new_spec.rb +41 -0
- data/spec/unit/ducktrap/class_methods/build_spec.rb +11 -0
- data/spec/unit/ducktrap/error/exception/pretty_inspect_spec.rb +22 -0
- data/spec/unit/ducktrap/error/pretty_inspect_spec.rb +19 -0
- data/spec/unit/ducktrap/evaluator/assert_successful_spec.rb +38 -0
- data/spec/unit/ducktrap/evaluator/invalid/output_spec.rb +14 -0
- data/spec/unit/ducktrap/evaluator/noop/output_spec.rb +14 -0
- data/spec/unit/ducktrap/evaluator/output_spec.rb +52 -0
- data/spec/unit/ducktrap/evaluator/pretty_inspect_spec.rb +63 -0
- data/spec/unit/ducktrap/evaluator/successful_predicate_spec.rb +36 -0
- data/spec/unit/ducktrap/failed_transformation_error/message_spec.rb +10 -0
- data/spec/unit/ducktrap/formatter/attribute_spec.rb +24 -0
- data/spec/unit/ducktrap/formatter/body_spec.rb +19 -0
- data/spec/unit/ducktrap/formatter/class_methods/new_spec.rb +14 -0
- data/spec/unit/ducktrap/formatter/initialize_spec.rb +14 -0
- data/spec/unit/ducktrap/formatter/name_spec.rb +25 -0
- data/spec/unit/ducktrap/formatter/nest_spec.rb +48 -0
- data/spec/unit/ducktrap/formatter/puts_spec.rb +36 -0
- data/spec/unit/ducktrap/mapper/builder/dumper_spec.rb +20 -0
- data/spec/unit/ducktrap/mapper/builder/loader_spec.rb +20 -0
- data/spec/unit/ducktrap/mapper/builder/object_spec.rb +90 -0
- data/spec/unit/ducktrap/mapper/class_methods/build_spec.rb +20 -0
- data/spec/unit/ducktrap/nary/builder/add_spec.rb +16 -0
- data/spec/unit/ducktrap/nary/builder/method_missing_spec.rb +44 -0
- data/spec/unit/ducktrap/nary/builder/output_spec.rb +16 -0
- data/spec/unit/ducktrap/nary/class_methods/build_spec.rb +22 -0
- data/spec/unit/ducktrap/nary/class_methods/included_spec.rb +13 -0
- data/spec/unit/ducktrap/nary/evaluator/output_spec.rb +79 -0
- data/spec/unit/ducktrap/nary/instance_methods/inverse_spec.rb +24 -0
- data/spec/unit/ducktrap/nary/instance_methods/pretty_inspect_spec.rb +31 -0
- data/spec/unit/ducktrap/node/anima/dump/evaluator/output_spec.rb +18 -0
- data/spec/unit/ducktrap/node/anima/dump/inverse_spec.rb +10 -0
- data/spec/unit/ducktrap/node/anima/dump/pretty_inspect_spec.rb +15 -0
- data/spec/unit/ducktrap/node/anima/evaluator/output_spec.rb +18 -0
- data/spec/unit/ducktrap/node/anima/load/evaluator/output_spec.rb +35 -0
- data/spec/unit/ducktrap/node/anima/load/inverse_spec.rb +10 -0
- data/spec/unit/ducktrap/node/anima/load/pretty_inspect_spec.rb +15 -0
- data/spec/unit/ducktrap/node/anima/pretty_inspect_spec.rb +15 -0
- data/spec/unit/ducktrap/node/block/evaluator/output_spec.rb +79 -0
- data/spec/unit/ducktrap/node/block/inverse_spec.rb +24 -0
- data/spec/unit/ducktrap/node/call_spec.rb +21 -0
- data/spec/unit/ducktrap/node/class_methods/build_spec.rb +11 -0
- data/spec/unit/ducktrap/node/class_methods/register_spec.rb +16 -0
- data/spec/unit/ducktrap/node/custom/builder/forward_spec.rb +54 -0
- data/spec/unit/ducktrap/node/custom/builder/inverse_spec.rb +54 -0
- data/spec/unit/ducktrap/node/custom/builder/object_spec.rb +54 -0
- data/spec/unit/ducktrap/node/custom/call_spec.rb +21 -0
- data/spec/unit/ducktrap/node/custom/class_methods/build_spec.rb +20 -0
- data/spec/unit/ducktrap/node/custom/inverse_spec.rb +12 -0
- data/spec/unit/ducktrap/node/custom/pretty_inspect_spec.rb +15 -0
- data/spec/unit/ducktrap/node/forward/evaluator/output_spec.rb +13 -0
- data/spec/unit/ducktrap/node/forward/inverse_spec.rb +14 -0
- data/spec/unit/ducktrap/node/forward/pretty_inspect_spec.rb +19 -0
- data/spec/unit/ducktrap/node/guard_nil/call_spec.rb +21 -0
- data/spec/unit/ducktrap/node/guard_nil/evaluator/output_spec.rb +27 -0
- data/spec/unit/ducktrap/node/guard_nil/inverse_spec.rb +12 -0
- data/spec/unit/ducktrap/node/hash/transform/evaluator/output_spec.rb +51 -0
- data/spec/unit/ducktrap/node/hash/transform/inverse_spec.rb +27 -0
- data/spec/unit/ducktrap/node/invalid/call_spec.rb +13 -0
- data/spec/unit/ducktrap/node/invalid/inverse_spec.rb +11 -0
- data/spec/unit/ducktrap/node/inverse/call_spec.rb +11 -0
- data/spec/unit/ducktrap/node/inverse/inverse_spec.rb +14 -0
- data/spec/unit/ducktrap/node/inverse/pretty_inspect_spec.rb +19 -0
- data/spec/unit/ducktrap/node/key/add/call_spec.rb +15 -0
- data/spec/unit/ducktrap/node/key/add/evaluator/call_spec.rb +15 -0
- data/spec/unit/ducktrap/node/key/add/inverse_spec.rb +14 -0
- data/spec/unit/ducktrap/node/key/delete/call_spec.rb +13 -0
- data/spec/unit/ducktrap/node/key/delete/evaluator/call_spec.rb +13 -0
- data/spec/unit/ducktrap/node/key/delete/inverse_spec.rb +13 -0
- data/spec/unit/ducktrap/node/key/dump/evaluator/output_spec.rb +37 -0
- data/spec/unit/ducktrap/node/key/dump/inverse_spec.rb +14 -0
- data/spec/unit/ducktrap/node/key/evaluator/key_spec.rb +26 -0
- data/spec/unit/ducktrap/node/key/fetch/evaluator/output_spec.rb +48 -0
- data/spec/unit/ducktrap/node/key/fetch/inverse_spec.rb +14 -0
- data/spec/unit/ducktrap/node/key/pretty_inspect_spec.rb +20 -0
- data/spec/unit/ducktrap/node/map/evaluator/output_spec.rb +22 -0
- data/spec/unit/ducktrap/node/map/inverse_spec.rb +15 -0
- data/spec/unit/ducktrap/node/noop/call_spec.rb +11 -0
- data/spec/unit/ducktrap/node/noop/inverse_spec.rb +9 -0
- data/spec/unit/ducktrap/node/pretty_inspect_spec.rb +17 -0
- data/spec/unit/ducktrap/node/primitive/call_spec.rb +19 -0
- data/spec/unit/ducktrap/node/primitive/inverse_spec.rb +13 -0
- data/spec/unit/ducktrap/node/primitive/pretty_inspect_spec.rb +15 -0
- data/spec/unit/ducktrap/node/run_spec.rb +46 -0
- data/spec/unit/ducktrap/node/static/call_spec.rb +13 -0
- data/spec/unit/ducktrap/node/static/inverse_spec.rb +14 -0
- data/spec/unit/ducktrap/nullary/class_methods/build_spec.rb +37 -0
- data/spec/unit/ducktrap/nullary/class_methods/included_spec.rb +7 -0
- data/spec/unit/ducktrap/pretty_dump/pretty_dump_spec.rb +47 -0
- data/spec/unit/ducktrap/pretty_dump/pretty_inspect_spec.rb +22 -0
- data/spec/unit/ducktrap/registry/lookup_spec.rb +27 -0
- data/spec/unit/ducktrap/registry/register_spec.rb +21 -0
- data/spec/unit/ducktrap/singleton/class_methods/included_spec.rb +13 -0
- data/spec/unit/ducktrap/singleton/class_methods/instance_spec.rb +19 -0
- data/spec/unit/ducktrap/singleton/instance_methods/inspect_spec.rb +19 -0
- data/spec/unit/ducktrap/singleton/instance_methods/pretty_inspect_spec.rb +17 -0
- data/spec/unit/ducktrap/unary/class_methods/build_spec.rb +18 -0
- data/spec/unit/ducktrap/unary/class_methods/included_spec.rb +14 -0
- data/spec/unit/ducktrap/unary/evaluator/output2_spec.rb +48 -0
- data/spec/unit/ducktrap/unary/evaluator/output_spec.rb +37 -0
- data/spec/unit/ducktrap/unary/instance_methods/pretty_inspect_spec.rb +15 -0
- metadata +399 -0
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Ducktrap::Node::Key::Delete, '#call' do
|
4
|
+
subject { object.call(input) }
|
5
|
+
|
6
|
+
let(:object) { described_class.new(inverse, key) }
|
7
|
+
let(:key) { mock('Key') }
|
8
|
+
|
9
|
+
let(:input) { { key => mock('Value') }.freeze }
|
10
|
+
let(:inverse) { mock('Inverse') }
|
11
|
+
|
12
|
+
its(:output) { should eql({}) }
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Ducktrap::Node::Key::Delete, '#call' do
|
4
|
+
subject { object.call(input) }
|
5
|
+
|
6
|
+
let(:object) { described_class.new(inverse, key) }
|
7
|
+
let(:key) { mock('Key') }
|
8
|
+
|
9
|
+
let(:input) { { key => mock('Value') }.freeze }
|
10
|
+
let(:inverse) { mock('Inverse') }
|
11
|
+
|
12
|
+
its(:output) { should eql({}) }
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Ducktrap::Node::Key::Delete, '#inverse' do
|
4
|
+
subject { object.inverse }
|
5
|
+
|
6
|
+
let(:object) { described_class.new(inverse, key) }
|
7
|
+
let(:key) { mock('Key') }
|
8
|
+
let(:inverse) { mock('Inverse') }
|
9
|
+
|
10
|
+
it { should eql(Ducktrap::Node::Key::Add.new(inverse, key)) }
|
11
|
+
|
12
|
+
it_should_behave_like 'an #inverse method'
|
13
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Ducktrap::Node::Key::Dump::Evaluator, '#output' do
|
4
|
+
|
5
|
+
let(:object) { described_class.new(context, input) }
|
6
|
+
let(:context) { mock('Context', :operand => operand, :key => key) }
|
7
|
+
let(:operand) { Ducktrap::Node::Noop.instance }
|
8
|
+
|
9
|
+
subject { object.output }
|
10
|
+
|
11
|
+
let(:key) { mock('Key', :frozen? => true) }
|
12
|
+
let(:value) { mock('Value', :frozen? => true) }
|
13
|
+
|
14
|
+
let(:input) { value }
|
15
|
+
|
16
|
+
context 'when operand does NOT modify value' do
|
17
|
+
|
18
|
+
it { should eql({ key => value}) }
|
19
|
+
it_should_behave_like 'an idempotent method'
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'when operand does modify value' do
|
24
|
+
let(:operand) { Ducktrap::Node::Static.new(:forward, :inversE) }
|
25
|
+
|
26
|
+
it { should eql({ key => :forward}) }
|
27
|
+
it_should_behave_like 'an idempotent method'
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'when operand fails' do
|
32
|
+
|
33
|
+
let(:operand) { Ducktrap::Node::Invalid.instance }
|
34
|
+
|
35
|
+
it { should eql(Ducktrap::Error.new(operand.call(value), input)) }
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Ducktrap::Node::Key::Dump, '#inverse' do
|
4
|
+
let(:object) { described_class.new(operand, key) }
|
5
|
+
|
6
|
+
let(:operand) { Ducktrap::Node::Static.new(:forward, :inverse) }
|
7
|
+
let(:key) { mock('Key') }
|
8
|
+
|
9
|
+
subject { object.inverse }
|
10
|
+
|
11
|
+
it { should eql(Ducktrap::Node::Key::Fetch.new(operand.inverse, key)) }
|
12
|
+
|
13
|
+
it_should_behave_like 'an #inverse method'
|
14
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Ducktrap::Node::Key::Evaluator, '#output' do
|
4
|
+
|
5
|
+
subject { object.key }
|
6
|
+
|
7
|
+
let(:object) { class_under_test.new(context, input) }
|
8
|
+
|
9
|
+
let(:class_under_test) do
|
10
|
+
Class.new(described_class) do
|
11
|
+
public :key
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:key) { mock('Key') }
|
16
|
+
let(:value) { mock('Value') }
|
17
|
+
|
18
|
+
let(:context) { mock('Context', :key => key, :operand => operand) }
|
19
|
+
let(:operand) { Ducktrap::Node::Static.new(:forward, :inverse) }
|
20
|
+
|
21
|
+
let(:input) { { key => value } }
|
22
|
+
|
23
|
+
it { should be(key) }
|
24
|
+
|
25
|
+
it_should_behave_like 'an idempotent method'
|
26
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Ducktrap::Node::Key::Fetch::Evaluator, '#output' do
|
4
|
+
|
5
|
+
let(:object) { described_class.new(context, input) }
|
6
|
+
let(:context) { mock('Context', :operand => operand, :key => key) }
|
7
|
+
let(:operand) { Ducktrap::Node::Noop.instance }
|
8
|
+
|
9
|
+
subject { object.output }
|
10
|
+
|
11
|
+
let(:key) { mock('Key', :frozen? => true) }
|
12
|
+
let(:value) { mock('Value', :frozen? => true) }
|
13
|
+
|
14
|
+
|
15
|
+
context 'when key is present' do
|
16
|
+
let(:input) { { key => value } }
|
17
|
+
|
18
|
+
context 'and operand does NOT modify value' do
|
19
|
+
|
20
|
+
it { should be(value) }
|
21
|
+
it_should_behave_like 'an idempotent method'
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'and operand does modify value' do
|
26
|
+
let(:operand) { Ducktrap::Node::Static.new(:forward, :inversE) }
|
27
|
+
|
28
|
+
it { should be(:forward) }
|
29
|
+
it_should_behave_like 'an idempotent method'
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'and operand fails' do
|
34
|
+
|
35
|
+
let(:operand) { Ducktrap::Node::Invalid.instance }
|
36
|
+
|
37
|
+
it { should eql(Ducktrap::Error.new(operand.call(value), input)) }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'when key is NOT present' do
|
42
|
+
let(:input) { {} }
|
43
|
+
|
44
|
+
it { should eql(Ducktrap::Error.new(context, input)) }
|
45
|
+
|
46
|
+
it_should_behave_like 'an idempotent method'
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Ducktrap::Node::Key::Fetch, '#inverse' do
|
4
|
+
let(:object) { described_class.new(operand, key) }
|
5
|
+
|
6
|
+
let(:operand) { Ducktrap::Node::Static.new(:forward, :inverse) }
|
7
|
+
let(:key) { mock('Key') }
|
8
|
+
|
9
|
+
subject { object.inverse }
|
10
|
+
|
11
|
+
it { should eql(Ducktrap::Node::Key::Dump.new(operand.inverse, key)) }
|
12
|
+
|
13
|
+
it_should_behave_like 'an #inverse method'
|
14
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Ducktrap::Node::Key, '#pretty_inspect' do
|
4
|
+
let(:object) { described_class.new(operand, key) }
|
5
|
+
let(:primitive) { String }
|
6
|
+
|
7
|
+
let(:operand) { Ducktrap::Node::Noop.instance }
|
8
|
+
let(:key) { :key }
|
9
|
+
|
10
|
+
subject { object.pretty_inspect }
|
11
|
+
|
12
|
+
it 'should return inspected error' do
|
13
|
+
should eql(strip(<<-STR))
|
14
|
+
Ducktrap::Node::Key
|
15
|
+
key: :key
|
16
|
+
operand:
|
17
|
+
Ducktrap::Node::Noop
|
18
|
+
STR
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Ducktrap::Node::Map::Evaluator, '#output' do
|
4
|
+
let(:object) { described_class.new(context, input) }
|
5
|
+
|
6
|
+
let(:context) { mock('Context', :operand => operand) }
|
7
|
+
let(:input) { [:foo, :bar ] }
|
8
|
+
|
9
|
+
subject { object.output }
|
10
|
+
|
11
|
+
context 'success' do
|
12
|
+
let(:operand) { Ducktrap::Node::Noop.instance }
|
13
|
+
|
14
|
+
it { should eql([:foo, :bar]) }
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'error' do
|
18
|
+
let(:operand) { Ducktrap::Node::Invalid.instance }
|
19
|
+
|
20
|
+
it { should eql(Ducktrap::Error.new(operand.call(:foo), input)) }
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Ducktrap::Node::Map, '#inverse' do
|
4
|
+
let(:object) { described_class.new(operand) }
|
5
|
+
|
6
|
+
let(:operand) do
|
7
|
+
Ducktrap::Node::Static.new(:foo, :bar)
|
8
|
+
end
|
9
|
+
|
10
|
+
subject { object.inverse }
|
11
|
+
|
12
|
+
it { should eql(described_class.new(operand.inverse)) }
|
13
|
+
|
14
|
+
it_should_behave_like 'an #inverse method'
|
15
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Ducktrap::Node, '#pretty_inspect' do
|
4
|
+
let(:object) { class_under_test.new }
|
5
|
+
|
6
|
+
let(:class_under_test) do
|
7
|
+
Class.new(described_class) do
|
8
|
+
def self.name
|
9
|
+
'Test'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
subject { object.pretty_inspect }
|
15
|
+
|
16
|
+
it { should eql("Test\n") }
|
17
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Ducktrap::Node::Primitive, '#call' do
|
4
|
+
let(:object) { described_class.new(primitive) }
|
5
|
+
|
6
|
+
let(:primitive) { String }
|
7
|
+
|
8
|
+
subject { object.call(input) }
|
9
|
+
|
10
|
+
context 'when input is kind of primitive' do
|
11
|
+
let(:input) { String.new }
|
12
|
+
it { should eql(Ducktrap::Evaluator::Noop.new(object, input)) }
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'when input is NOT kind of primitive' do
|
16
|
+
let(:input) { [] }
|
17
|
+
it { should eql(Ducktrap::Evaluator::Invalid.new(object, input)) }
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Ducktrap::Node::Primitive, '#inverse' do
|
4
|
+
let(:object) { described_class.new(primitive) }
|
5
|
+
|
6
|
+
let(:primitive) { mock('Primitive') }
|
7
|
+
|
8
|
+
subject { object.inverse }
|
9
|
+
|
10
|
+
it { should be(object) }
|
11
|
+
|
12
|
+
it_should_behave_like 'an #inverse method'
|
13
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Ducktrap::Node::Primitive, '#pretty_inspect' do
|
4
|
+
let(:object) { described_class.new(primitive) }
|
5
|
+
let(:primitive) { String }
|
6
|
+
|
7
|
+
subject { object.pretty_inspect }
|
8
|
+
|
9
|
+
it 'should return inspected error' do
|
10
|
+
should eql(strip(<<-STR))
|
11
|
+
Ducktrap::Node::Primitive
|
12
|
+
primitive: String
|
13
|
+
STR
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Ducktrap::Node, '#run' do
|
4
|
+
subject { object.run(input) }
|
5
|
+
|
6
|
+
let(:object) { class_under_test.new }
|
7
|
+
|
8
|
+
let(:class_under_test) do
|
9
|
+
evaluator = self.evaluator
|
10
|
+
Class.new(described_class) do
|
11
|
+
define_method :call do |input|
|
12
|
+
evaluator
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class Evaluator
|
18
|
+
attr_reader :output
|
19
|
+
|
20
|
+
def initialize(output, successful)
|
21
|
+
@output, @successful = output, successful
|
22
|
+
end
|
23
|
+
|
24
|
+
def assert_successful
|
25
|
+
raise unless @successful
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
let(:evaluator) { Evaluator.new(output, successful?) }
|
30
|
+
let(:input) { mock('Input') }
|
31
|
+
let(:output) { mock('Output') }
|
32
|
+
|
33
|
+
context 'when evaluator is successful' do
|
34
|
+
let(:successful?) { true }
|
35
|
+
|
36
|
+
it { should be(output) }
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'when evaluator is NOT successful' do
|
40
|
+
let(:successful?) { false }
|
41
|
+
|
42
|
+
it 'should raise error' do
|
43
|
+
expect { subject }.to raise_error
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Ducktrap::Node::Static, '#call' do
|
4
|
+
let(:object) { described_class.new(value, inverse_value) }
|
5
|
+
|
6
|
+
let(:value) { mock('Value') }
|
7
|
+
let(:inverse_value) { mock('Inverse Value') }
|
8
|
+
let(:input) { mock('Input') }
|
9
|
+
|
10
|
+
subject { object.call(input) }
|
11
|
+
|
12
|
+
it { should eql(Ducktrap::Evaluator::Static.new(object, input, value)) }
|
13
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Ducktrap::Node::Static, '#inverse' do
|
4
|
+
let(:object) { described_class.new(value, inverse_value) }
|
5
|
+
|
6
|
+
let(:value) { mock('Value') }
|
7
|
+
let(:inverse_value) { mock('Inverse Value') }
|
8
|
+
|
9
|
+
subject { object.inverse }
|
10
|
+
|
11
|
+
it { should eql(Ducktrap::Node::Static.new(inverse_value, value)) }
|
12
|
+
|
13
|
+
it_should_behave_like 'an #inverse method'
|
14
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Ducktrap::Nullary::ClassMethods, '#build' do
|
4
|
+
let(:object) do
|
5
|
+
Class.new do
|
6
|
+
include Equalizer.new(:arguments)
|
7
|
+
extend Ducktrap::Nullary::ClassMethods
|
8
|
+
attr_reader :arguments
|
9
|
+
def initialize(*arguments)
|
10
|
+
@arguments = arguments
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.name
|
14
|
+
'Test'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
subject { object.build(*arguments, &block) }
|
20
|
+
|
21
|
+
context 'with arguments' do
|
22
|
+
let(:arguments) { [:foo, :bar] }
|
23
|
+
let(:block) { nil }
|
24
|
+
|
25
|
+
it { should eql(object.new(:foo, :bar)) }
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'with block' do
|
29
|
+
let(:arguments) { [] }
|
30
|
+
let(:block) { proc {} }
|
31
|
+
|
32
|
+
it 'should raise error' do
|
33
|
+
expect { subject }.to raise_error(RuntimeError, 'Test.build does not take a block')
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|