exel 1.4.0 → 1.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.codeclimate.yml +4 -4
- data/.rubocop.yml +20 -12
- data/.rubocop_airbnb.yml +2 -0
- data/.travis.yml +17 -4
- data/Gemfile +1 -2
- data/Gemfile.lock +64 -60
- data/README.md +1 -1
- data/Rakefile +1 -0
- data/exel.gemspec +4 -4
- data/lib/exel.rb +1 -0
- data/lib/exel/ast_node.rb +2 -1
- data/lib/exel/context.rb +2 -1
- data/lib/exel/deferred_context_value.rb +1 -0
- data/lib/exel/error/job_termination.rb +1 -0
- data/lib/exel/events.rb +1 -0
- data/lib/exel/instruction.rb +2 -1
- data/lib/exel/instruction_node.rb +1 -0
- data/lib/exel/job.rb +6 -4
- data/lib/exel/listen_instruction.rb +1 -0
- data/lib/exel/logging.rb +1 -0
- data/lib/exel/logging/logger_wrapper.rb +4 -1
- data/lib/exel/logging_helper.rb +1 -0
- data/lib/exel/middleware/chain.rb +1 -0
- data/lib/exel/middleware/logging.rb +1 -1
- data/lib/exel/null_instruction.rb +1 -0
- data/lib/exel/processor_helper.rb +1 -0
- data/lib/exel/processors/run_processor.rb +1 -0
- data/lib/exel/processors/split_processor.rb +2 -1
- data/lib/exel/providers/local_file_provider.rb +2 -1
- data/lib/exel/providers/threaded_async_provider.rb +1 -0
- data/lib/exel/sequence_node.rb +1 -0
- data/lib/exel/value.rb +1 -0
- data/lib/exel/version.rb +2 -1
- data/spec/exel/ast_node_spec.rb +42 -42
- data/spec/exel/context_spec.rb +76 -77
- data/spec/exel/deferred_context_value_spec.rb +41 -42
- data/spec/exel/events_spec.rb +65 -65
- data/spec/exel/instruction_node_spec.rb +16 -16
- data/spec/exel/instruction_spec.rb +46 -45
- data/spec/exel/job_spec.rb +94 -91
- data/spec/exel/listen_instruction_spec.rb +10 -10
- data/spec/exel/logging/logger_wrapper_spec.rb +67 -69
- data/spec/exel/logging_helper_spec.rb +15 -16
- data/spec/exel/logging_spec.rb +56 -56
- data/spec/exel/middleware/chain_spec.rb +51 -53
- data/spec/exel/middleware/logging_spec.rb +21 -23
- data/spec/exel/middleware_spec.rb +49 -50
- data/spec/exel/null_instruction_spec.rb +3 -4
- data/spec/exel/processors/async_processor_spec.rb +16 -18
- data/spec/exel/processors/run_processor_spec.rb +9 -11
- data/spec/exel/processors/split_processor_spec.rb +91 -93
- data/spec/exel/providers/local_file_provider_spec.rb +25 -28
- data/spec/exel/providers/threaded_async_provider_spec.rb +36 -38
- data/spec/exel/sequence_node_spec.rb +11 -11
- data/spec/exel/value_spec.rb +32 -33
- data/spec/exel_spec.rb +8 -7
- data/spec/integration/integration_spec.rb +2 -1
- data/spec/spec_helper.rb +3 -2
- data/spec/support/integration_test_classes.rb +3 -1
- metadata +16 -30
data/spec/exel/events_spec.rb
CHANGED
@@ -1,97 +1,97 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
module EXEL
|
3
|
-
describe Events do
|
4
|
-
class EventTest
|
5
|
-
include Events
|
6
2
|
|
7
|
-
|
8
|
-
|
9
|
-
|
3
|
+
describe EXEL::Events do
|
4
|
+
class EventTest
|
5
|
+
include EXEL::Events
|
6
|
+
|
7
|
+
def initialize(context)
|
8
|
+
@context = context
|
10
9
|
end
|
10
|
+
end
|
11
11
|
|
12
|
-
|
13
|
-
let(:event_listener) { double(:event_listener) }
|
14
|
-
let(:context) { EXEL::Context.new(Events::LISTENERS_KEY => {event: [event_listener]}) }
|
12
|
+
subject(:events) { EventTest.new(context) }
|
15
13
|
|
16
|
-
|
17
|
-
|
18
|
-
end
|
14
|
+
let(:event_listener) { double(:event_listener) }
|
15
|
+
let(:context) { EXEL::Context.new(EXEL::Events::LISTENERS_KEY => {event: [event_listener]}) }
|
19
16
|
|
20
|
-
|
21
|
-
|
22
|
-
|
17
|
+
it 'defines an attr_reader for context on the class it is included in' do
|
18
|
+
expect(events.context).to eq(context)
|
19
|
+
end
|
23
20
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
end
|
28
|
-
end
|
21
|
+
describe '#register_listener' do
|
22
|
+
context 'when no listeners have been defined' do
|
23
|
+
let(:context) { EXEL::Context.new }
|
29
24
|
|
30
|
-
it '
|
31
|
-
|
32
|
-
|
33
|
-
expect(context[Events::LISTENERS_KEY].fetch(:event)).to contain_exactly(event_listener, new_listener)
|
25
|
+
it 'adds a new listener to the context' do
|
26
|
+
events.register_listener(context, :event, event_listener)
|
27
|
+
expect(context[EXEL::Events::LISTENERS_KEY].fetch(:event)).to contain_exactly(event_listener)
|
34
28
|
end
|
35
29
|
end
|
36
30
|
|
37
|
-
|
38
|
-
|
39
|
-
|
31
|
+
it 'registers multiple listeners for the same event' do
|
32
|
+
new_listener = double(:event_listener2)
|
33
|
+
events.register_listener(context, :event, new_listener)
|
34
|
+
expect(context[EXEL::Events::LISTENERS_KEY].fetch(:event)).to contain_exactly(event_listener, new_listener)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '#trigger' do
|
39
|
+
let(:context) { EXEL::Context.new }
|
40
|
+
let(:data) { {foo: 1} }
|
40
41
|
|
41
|
-
|
42
|
+
before { allow(events).to receive(:context).and_return(context) }
|
42
43
|
|
43
|
-
|
44
|
-
|
45
|
-
|
44
|
+
context 'when no events have been registered' do
|
45
|
+
it 'does not trigger anything' do
|
46
|
+
expect(event_listener).not_to receive(:event)
|
46
47
|
|
47
|
-
|
48
|
-
end
|
48
|
+
events.trigger(:event, data)
|
49
49
|
end
|
50
|
+
end
|
50
51
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
52
|
+
context 'with a single listener registered for the event' do
|
53
|
+
before do
|
54
|
+
events.register_listener(context, :event, event_listener)
|
55
|
+
end
|
55
56
|
|
56
|
-
|
57
|
-
|
57
|
+
it 'calls the listener with the context and event data' do
|
58
|
+
expect(event_listener).to receive(:event).with(context, data)
|
58
59
|
|
59
|
-
|
60
|
-
|
60
|
+
events.trigger(:event, data)
|
61
|
+
end
|
61
62
|
|
62
|
-
|
63
|
-
|
63
|
+
it 'passes an empty hash if no data was given' do
|
64
|
+
expect(event_listener).to receive(:event).with(context, {})
|
64
65
|
|
65
|
-
|
66
|
-
end
|
66
|
+
events.trigger(:event)
|
67
67
|
end
|
68
|
+
end
|
68
69
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
70
|
+
context 'with no listeners registered for the event' do
|
71
|
+
before do
|
72
|
+
events.register_listener(context, :other_event, event_listener)
|
73
|
+
end
|
73
74
|
|
74
|
-
|
75
|
-
|
75
|
+
it 'does not trigger anything' do
|
76
|
+
expect(event_listener).not_to receive(:event)
|
76
77
|
|
77
|
-
|
78
|
-
end
|
78
|
+
events.trigger(:event, data)
|
79
79
|
end
|
80
|
+
end
|
80
81
|
|
81
|
-
|
82
|
-
|
82
|
+
context 'with multiple listeners registered for the event' do
|
83
|
+
let(:event_listener2) { double(:event_listener2) }
|
83
84
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
85
|
+
before do
|
86
|
+
events.register_listener(context, :event, event_listener)
|
87
|
+
events.register_listener(context, :event, event_listener2)
|
88
|
+
end
|
88
89
|
|
89
|
-
|
90
|
-
|
91
|
-
|
90
|
+
it 'calls each listener with the context and event data' do
|
91
|
+
expect(event_listener).to receive(:event).with(context, data)
|
92
|
+
expect(event_listener2).to receive(:event).with(context, data)
|
92
93
|
|
93
|
-
|
94
|
-
end
|
94
|
+
events.trigger(:event, data)
|
95
95
|
end
|
96
96
|
end
|
97
97
|
end
|
@@ -1,23 +1,23 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
module EXEL
|
3
|
-
describe InstructionNode do
|
4
|
-
let(:context) { {} }
|
5
|
-
let(:instruction) { instance_double(Instruction, execute: nil) }
|
6
|
-
let(:child) { instance_double(ASTNode) }
|
7
|
-
subject(:node) { InstructionNode.new(instruction, [child]) }
|
8
2
|
|
9
|
-
|
3
|
+
describe EXEL::InstructionNode do
|
4
|
+
subject(:node) { EXEL::InstructionNode.new(instruction, children: [child]) }
|
10
5
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
node.run(context)
|
15
|
-
end
|
6
|
+
let(:context) { {} }
|
7
|
+
let(:instruction) { instance_double(EXEL::Instruction, execute: nil) }
|
8
|
+
let(:child) { instance_double(EXEL::ASTNode) }
|
16
9
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
10
|
+
it { is_expected.to be_kind_of(EXEL::ASTNode) }
|
11
|
+
|
12
|
+
describe '#run' do
|
13
|
+
it 'only executes the instruction' do
|
14
|
+
expect(instruction).to receive(:execute).with(context).once
|
15
|
+
node.run(context)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'does not run it`s children' do
|
19
|
+
expect(child).not_to receive(:run)
|
20
|
+
node.run(context)
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
@@ -1,63 +1,64 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
module EXEL
|
3
|
-
describe Instruction do
|
4
|
-
subject(:instruction) { EXEL::Instruction.new(processor_class, args) }
|
5
|
-
let(:processor_class) { double(:processor_class, new: processor_instance) }
|
6
|
-
let(:processor_instance) { double(:processor_instance, process: nil) }
|
7
|
-
let(:args) { {arg1: 'arg_value1', arg2: {}} }
|
8
|
-
let(:context) { {context_key: 'context_value'} }
|
9
2
|
|
10
|
-
|
11
|
-
|
12
|
-
expect(processor_class).to receive(:new).and_return(processor_instance)
|
13
|
-
expect(processor_instance).to receive(:process)
|
3
|
+
describe EXEL::Instruction do
|
4
|
+
subject(:instruction) { EXEL::Instruction.new(processor_class, args) }
|
14
5
|
|
15
|
-
|
16
|
-
|
6
|
+
let(:processor_class) { double(:processor_class, new: processor_instance) }
|
7
|
+
let(:processor_instance) { double(:processor_instance, process: nil) }
|
8
|
+
let(:args) { {arg1: 'arg_value1', arg2: {}} }
|
9
|
+
let(:context) { {context_key: 'context_value'} }
|
17
10
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
11
|
+
describe '#execute' do
|
12
|
+
it 'calls process on an instance of the processor class' do
|
13
|
+
expect(processor_class).to receive(:new).and_return(processor_instance)
|
14
|
+
expect(processor_instance).to receive(:process)
|
22
15
|
|
23
|
-
|
24
|
-
|
25
|
-
expect(context_arg).to be(context)
|
26
|
-
processor_instance
|
27
|
-
end
|
16
|
+
instruction.execute(context)
|
17
|
+
end
|
28
18
|
|
29
|
-
|
30
|
-
|
19
|
+
it 'invokes the middleware chain' do
|
20
|
+
expect(EXEL.middleware).to receive(:invoke).with(processor_class, context, args)
|
21
|
+
instruction.execute(context)
|
22
|
+
end
|
31
23
|
|
32
|
-
|
33
|
-
|
34
|
-
expect(
|
24
|
+
it 'does not pass a copy of the context' do
|
25
|
+
allow(processor_class).to receive(:new) do |context_arg|
|
26
|
+
expect(context_arg).to be(context)
|
27
|
+
processor_instance
|
35
28
|
end
|
36
29
|
|
37
|
-
context
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
30
|
+
instruction.execute(context)
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'adds args to the context' do
|
34
|
+
instruction.execute(context)
|
35
|
+
expect(context.keys).to include(*args.keys)
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'with args' do
|
39
|
+
it 'passes the args to the processor' do
|
40
|
+
expect(processor_class).to receive(:new).with(hash_including(args))
|
41
|
+
instruction.execute(context)
|
42
42
|
end
|
43
|
+
end
|
43
44
|
|
44
|
-
|
45
|
-
|
45
|
+
context 'without args' do
|
46
|
+
let(:args) { nil }
|
46
47
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
end
|
48
|
+
it 'passes only the context to the processor' do
|
49
|
+
expect(processor_class).to receive(:new).with(context)
|
50
|
+
instruction.execute(context)
|
51
51
|
end
|
52
|
+
end
|
52
53
|
|
53
|
-
|
54
|
-
|
55
|
-
subject(:instruction) { EXEL::Instruction.new(processor_class, args, subtree) }
|
54
|
+
context 'with a subtree' do
|
55
|
+
subject(:instruction) { EXEL::Instruction.new(processor_class, args, subtree: subtree) }
|
56
56
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
57
|
+
let(:subtree) { double(:subtree) }
|
58
|
+
|
59
|
+
it 'passes the subtree to the processor' do
|
60
|
+
expect(processor_instance).to receive(:process).with(subtree)
|
61
|
+
instruction.execute(context)
|
61
62
|
end
|
62
63
|
end
|
63
64
|
end
|
data/spec/exel/job_spec.rb
CHANGED
@@ -1,116 +1,119 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
module EXEL
|
3
|
-
describe Job do
|
4
|
-
describe '.define' do
|
5
|
-
let(:ast) { instance_double(SequenceNode, run: nil, start: nil) }
|
6
|
-
let(:block) { proc {} }
|
7
2
|
|
8
|
-
|
3
|
+
describe EXEL::Job do
|
4
|
+
describe '.define' do
|
5
|
+
let(:ast) { instance_double(EXEL::SequenceNode, run: nil, start: nil) }
|
6
|
+
let(:block) { proc {} }
|
7
|
+
|
8
|
+
after { EXEL::Job.registry.clear }
|
9
|
+
|
10
|
+
it 'registers job definitions' do
|
11
|
+
EXEL::Job.define :test_job, &block
|
12
|
+
expect(EXEL::Job.registry[:test_job]).to eq(block)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'raises an exception if a job name is already in use' do
|
16
|
+
EXEL::Job.define :test_job, &block
|
17
|
+
expect { EXEL::Job.define :test_job, &block }.to raise_error 'Job :test_job is already defined'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '.run' do
|
22
|
+
let(:ast) { instance_double(EXEL::SequenceNode, run: nil, start: nil) }
|
23
|
+
let(:context) { instance_double(EXEL::Context) }
|
24
|
+
|
25
|
+
context 'with a string of DSL code' do
|
26
|
+
it 'parses the code' do
|
27
|
+
dsl_code = 'code'
|
28
|
+
expect(EXEL::Job::Parser).to receive(:parse).with(dsl_code).and_return(ast)
|
29
|
+
EXEL::Job.run(dsl_code, context)
|
30
|
+
end
|
9
31
|
|
10
|
-
it '
|
11
|
-
Job.
|
12
|
-
expect(
|
32
|
+
it 'runs the AST returned by the parser' do
|
33
|
+
allow(EXEL::Job::Parser).to receive(:parse).and_return(ast)
|
34
|
+
expect(ast).to receive(:start).with(context)
|
35
|
+
EXEL::Job.run('code', context)
|
13
36
|
end
|
14
37
|
|
15
|
-
it '
|
16
|
-
Job.
|
17
|
-
|
38
|
+
it 'returns the context' do
|
39
|
+
allow(EXEL::Job::Parser).to receive(:parse).and_return(ast)
|
40
|
+
result = EXEL::Job.run('code', context)
|
41
|
+
expect(result).to be(context)
|
18
42
|
end
|
19
43
|
end
|
20
44
|
|
21
|
-
|
22
|
-
|
23
|
-
|
45
|
+
context 'with a job name' do
|
46
|
+
context 'of a defined job' do
|
47
|
+
let(:block) { proc {} }
|
24
48
|
|
25
|
-
|
26
|
-
|
27
|
-
dsl_code = 'code'
|
28
|
-
expect(Job::Parser).to receive(:parse).with(dsl_code).and_return(ast)
|
29
|
-
Job.run(dsl_code, context)
|
49
|
+
before do
|
50
|
+
allow(EXEL::Job).to receive(:registry).and_return(test_job: block)
|
30
51
|
end
|
31
52
|
|
32
|
-
it 'runs the
|
33
|
-
|
53
|
+
it 'runs the job' do
|
54
|
+
expect(EXEL::Job::Parser).to receive(:parse).with(block).and_return(ast)
|
34
55
|
expect(ast).to receive(:start).with(context)
|
35
|
-
Job.run(
|
56
|
+
EXEL::Job.run(:test_job, context)
|
36
57
|
end
|
37
58
|
|
38
59
|
it 'returns the context' do
|
39
|
-
|
40
|
-
result = Job.run('code', context)
|
60
|
+
result = EXEL::Job.run(:test_job, context)
|
41
61
|
expect(result).to be(context)
|
42
62
|
end
|
43
63
|
end
|
44
64
|
|
45
|
-
context '
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
it 'runs the job' do
|
54
|
-
expect(Job::Parser).to receive(:parse).with(block).and_return(ast)
|
55
|
-
expect(ast).to receive(:start).with(context)
|
56
|
-
Job.run(:test_job, context)
|
57
|
-
end
|
65
|
+
context 'of a undefined job' do
|
66
|
+
it 'returns nil' do
|
67
|
+
expect { EXEL::Job.run(:test_job, context) }.to raise_error('Job "test_job" not found')
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
58
72
|
|
59
|
-
|
60
|
-
|
61
|
-
|
73
|
+
describe 'mutation of arguments' do
|
74
|
+
module EXEL
|
75
|
+
module Processors
|
76
|
+
class TestProcessor
|
77
|
+
def initialize(context)
|
78
|
+
context[:array] << context[:arg]
|
62
79
|
end
|
63
|
-
end
|
64
80
|
|
65
|
-
|
66
|
-
it 'returns nil' do
|
67
|
-
expect { Job.run(:test_job, context) }.to raise_error('Job "test_job" not found')
|
81
|
+
def process(_callback)
|
68
82
|
end
|
69
83
|
end
|
70
84
|
end
|
71
85
|
end
|
72
86
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
context[:array] << context[:arg]
|
77
|
-
end
|
78
|
-
|
79
|
-
def process(_callback)
|
80
|
-
end
|
87
|
+
it 'does not persist between runs' do
|
88
|
+
EXEL::Job.define :test do
|
89
|
+
process with: EXEL::Processors::TestProcessor, array: [], arg: context[:value]
|
81
90
|
end
|
82
91
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
end
|
87
|
-
|
88
|
-
context = Context.new(value: 1)
|
89
|
-
Job.run(:test, context)
|
90
|
-
expect(context[:array]).to eq([1])
|
92
|
+
context = EXEL::Context.new(value: 1)
|
93
|
+
EXEL::Job.run(:test, context)
|
94
|
+
expect(context[:array]).to eq([1])
|
91
95
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
end
|
96
|
+
context = EXEL::Context.new(value: 2)
|
97
|
+
EXEL::Job.run(:test, context)
|
98
|
+
expect(context[:array]).to eq([2])
|
96
99
|
end
|
97
100
|
end
|
98
101
|
|
99
|
-
describe Job::Parser do
|
100
|
-
let(:parser) { Job::Parser.new }
|
101
|
-
let(:ast) { instance_double(SequenceNode, run: nil) }
|
102
|
+
describe EXEL::Job::Parser do
|
103
|
+
let(:parser) { EXEL::Job::Parser.new }
|
104
|
+
let(:ast) { instance_double(EXEL::SequenceNode, run: nil) }
|
102
105
|
|
103
106
|
describe '#initialize' do
|
104
107
|
it 'initializes a sequence node' do
|
105
|
-
expect(parser.ast).to be_kind_of(SequenceNode)
|
108
|
+
expect(parser.ast).to be_kind_of(EXEL::SequenceNode)
|
106
109
|
end
|
107
110
|
end
|
108
111
|
|
109
112
|
describe '.parse' do
|
110
|
-
let(:parser) { instance_double(Job::Parser, ast: ast, instance_eval: nil) }
|
113
|
+
let(:parser) { instance_double(EXEL::Job::Parser, ast: ast, instance_eval: nil) }
|
111
114
|
|
112
115
|
before do
|
113
|
-
allow(Job::Parser).to receive(:new).and_return(parser)
|
116
|
+
allow(EXEL::Job::Parser).to receive(:new).and_return(parser)
|
114
117
|
end
|
115
118
|
|
116
119
|
context 'given DSL code as a proc' do
|
@@ -120,7 +123,7 @@ module EXEL
|
|
120
123
|
expect(block).to eq(dsl_proc)
|
121
124
|
end
|
122
125
|
|
123
|
-
Job::Parser.parse(dsl_proc)
|
126
|
+
EXEL::Job::Parser.parse(dsl_proc)
|
124
127
|
end
|
125
128
|
end
|
126
129
|
|
@@ -129,12 +132,12 @@ module EXEL
|
|
129
132
|
dsl_code = 'code'
|
130
133
|
expect(parser).to receive(:instance_eval).with(dsl_code)
|
131
134
|
|
132
|
-
Job::Parser.parse(dsl_code)
|
135
|
+
EXEL::Job::Parser.parse(dsl_code)
|
133
136
|
end
|
134
137
|
end
|
135
138
|
|
136
139
|
it 'returns the parsed AST' do
|
137
|
-
expect(Job::Parser.parse(proc {})).to eq(ast)
|
140
|
+
expect(EXEL::Job::Parser.parse(proc {})).to eq(ast)
|
138
141
|
end
|
139
142
|
end
|
140
143
|
|
@@ -142,18 +145,18 @@ module EXEL
|
|
142
145
|
let(:block) { proc {} }
|
143
146
|
let(:processor_class) { class_double(Class) }
|
144
147
|
|
145
|
-
before { allow(Job::Parser).to receive(:parse).and_return(ast) }
|
148
|
+
before { allow(EXEL::Job::Parser).to receive(:parse).and_return(ast) }
|
146
149
|
|
147
150
|
context 'without a block' do
|
148
151
|
it 'creates a process instruction' do
|
149
|
-
expect(Instruction).to receive(:new).with(processor_class, {arg1: 'arg1_value'}, nil)
|
152
|
+
expect(EXEL::Instruction).to receive(:new).with(processor_class, {arg1: 'arg1_value'}, subtree: nil)
|
150
153
|
|
151
154
|
parser.process with: processor_class, arg1: 'arg1_value'
|
152
155
|
end
|
153
156
|
|
154
157
|
it 'appends an instruction node to the AST with no children' do
|
155
158
|
expect(parser.ast).to receive(:add_child) do |node|
|
156
|
-
expect(node).to be_a_kind_of(InstructionNode)
|
159
|
+
expect(node).to be_a_kind_of(EXEL::InstructionNode)
|
157
160
|
expect(node.children).to eq([])
|
158
161
|
end
|
159
162
|
|
@@ -163,15 +166,15 @@ module EXEL
|
|
163
166
|
|
164
167
|
context 'with a block' do
|
165
168
|
it 'passes the parsed subtree to the instruction' do
|
166
|
-
expect(Job::Parser).to receive(:parse).with(block).and_return(ast)
|
167
|
-
expect(Instruction).to receive(:new).with(processor_class, {arg1: 'arg1_value'}, ast)
|
169
|
+
expect(EXEL::Job::Parser).to receive(:parse).with(block).and_return(ast)
|
170
|
+
expect(EXEL::Instruction).to receive(:new).with(processor_class, {arg1: 'arg1_value'}, subtree: ast)
|
168
171
|
|
169
172
|
parser.process with: processor_class, arg1: 'arg1_value', &block
|
170
173
|
end
|
171
174
|
|
172
175
|
it 'appends an instruction node to the AST with the parsed block as its subtree' do
|
173
176
|
expect(parser.ast).to receive(:add_child) do |node|
|
174
|
-
expect(node).to be_a_kind_of(InstructionNode)
|
177
|
+
expect(node).to be_a_kind_of(EXEL::InstructionNode)
|
175
178
|
expect(node.children).to eq([ast])
|
176
179
|
end
|
177
180
|
|
@@ -181,30 +184,30 @@ module EXEL
|
|
181
184
|
end
|
182
185
|
|
183
186
|
[
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
+
{method: :async, processor: EXEL::Processors::AsyncProcessor},
|
188
|
+
{method: :split, processor: EXEL::Processors::SplitProcessor},
|
189
|
+
{method: :run, processor: EXEL::Processors::RunProcessor},
|
187
190
|
].each do |data|
|
188
191
|
describe "##{data[:method]}" do
|
189
192
|
before do
|
190
|
-
allow(Job::Parser).to receive(:parse).and_return(ast)
|
193
|
+
allow(EXEL::Job::Parser).to receive(:parse).and_return(ast)
|
191
194
|
end
|
192
195
|
|
193
196
|
it "creates a #{data[:method]} instruction" do
|
194
|
-
expect(Instruction).to receive(:new).with(data[:processor], {arg1: 'arg1_value'}, ast)
|
197
|
+
expect(EXEL::Instruction).to receive(:new).with(data[:processor], {arg1: 'arg1_value'}, subtree: ast)
|
195
198
|
parser.send(data[:method], arg1: 'arg1_value') {}
|
196
199
|
end
|
197
200
|
|
198
201
|
it 'parses the block given' do
|
199
202
|
block = -> {}
|
200
|
-
expect(Job::Parser).to receive(:parse).with(block).and_return(ast)
|
203
|
+
expect(EXEL::Job::Parser).to receive(:parse).with(block).and_return(ast)
|
201
204
|
|
202
205
|
parser.send(data[:method], &block)
|
203
206
|
end
|
204
207
|
|
205
208
|
it 'adds parsed subtree and instruction to the AST' do
|
206
209
|
expect(parser.ast).to receive(:add_child) do |node|
|
207
|
-
expect(node).to be_a_kind_of(InstructionNode)
|
210
|
+
expect(node).to be_a_kind_of(EXEL::InstructionNode)
|
208
211
|
expect(node.children).to eq([ast])
|
209
212
|
end
|
210
213
|
|
@@ -215,7 +218,7 @@ module EXEL
|
|
215
218
|
|
216
219
|
describe '#context' do
|
217
220
|
it 'returns a DeferredContextValue' do
|
218
|
-
expect(parser.context).to be_a_kind_of(DeferredContextValue)
|
221
|
+
expect(parser.context).to be_a_kind_of(EXEL::DeferredContextValue)
|
219
222
|
end
|
220
223
|
end
|
221
224
|
|
@@ -223,15 +226,15 @@ module EXEL
|
|
223
226
|
let(:listener_class) { class_double(Class) }
|
224
227
|
|
225
228
|
it 'creates a listen instruction' do
|
226
|
-
expect(ListenInstruction).to receive(:new).with(:event, listener_class)
|
229
|
+
expect(EXEL::ListenInstruction).to receive(:new).with(:event, listener_class)
|
227
230
|
parser.listen for: :event, with: listener_class
|
228
231
|
end
|
229
232
|
|
230
233
|
it 'adds an InstructionNode containing the listen instruction' do
|
231
234
|
parser.listen for: :event, with: listener_class
|
232
235
|
node = parser.ast.children.first
|
233
|
-
expect(node).to be_a_kind_of(InstructionNode)
|
234
|
-
expect(node.instruction).to be_a_kind_of(ListenInstruction)
|
236
|
+
expect(node).to be_a_kind_of(EXEL::InstructionNode)
|
237
|
+
expect(node.instruction).to be_a_kind_of(EXEL::ListenInstruction)
|
235
238
|
end
|
236
239
|
end
|
237
240
|
end
|