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
@@ -1,15 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
module EXEL
|
3
|
-
describe ListenInstruction do
|
4
|
-
subject(:instruction) { EXEL::ListenInstruction.new(:event, listener) }
|
5
|
-
let(:listener) { double(:listener) }
|
6
|
-
let(:context) { EXEL::Context.new }
|
7
2
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
3
|
+
describe EXEL::ListenInstruction do
|
4
|
+
subject(:instruction) { EXEL::ListenInstruction.new(:event, listener) }
|
5
|
+
|
6
|
+
let(:listener) { double(:listener) }
|
7
|
+
let(:context) { EXEL::Context.new }
|
8
|
+
|
9
|
+
describe '#execute' do
|
10
|
+
it 'registers the event listener' do
|
11
|
+
expect(instruction).to receive(:register_listener).with(context, :event, listener)
|
12
|
+
instruction.execute(context)
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
@@ -1,94 +1,92 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
module EXEL
|
3
|
-
module Logging
|
4
|
-
describe LoggerWrapper do
|
5
|
-
subject(:wrapper) { LoggerWrapper.new(logger) }
|
6
|
-
let(:logger) { instance_double(Logger) }
|
7
|
-
|
8
|
-
it { is_expected.to be_a(SimpleDelegator) }
|
9
|
-
|
10
|
-
LOG_LEVELS = %i(debug info warn error fatal unknown).freeze
|
11
|
-
|
12
|
-
context 'without a Logging prefix' do
|
13
|
-
LOG_LEVELS.each do |level|
|
14
|
-
describe "##{level}" do
|
15
|
-
context 'when passed a message string' do
|
16
|
-
it 'passes the message to its wrapped logger' do
|
17
|
-
expect(logger).to receive(level).with('message')
|
18
|
-
wrapper.send(level, 'message')
|
19
|
-
end
|
20
|
-
end
|
21
2
|
|
22
|
-
|
23
|
-
|
24
|
-
block = proc {}
|
25
|
-
expect(logger).to receive(level).with(nil, &block)
|
3
|
+
describe EXEL::Logging::LoggerWrapper do
|
4
|
+
subject(:wrapper) { EXEL::Logging::LoggerWrapper.new(logger) }
|
26
5
|
|
27
|
-
|
28
|
-
end
|
6
|
+
let(:logger) { instance_double(Logger) }
|
29
7
|
|
30
|
-
|
31
|
-
it 'passes the block and progname to its wrapped logger' do
|
32
|
-
block = proc {}
|
33
|
-
expect(logger).to receive(level).with('test', &block)
|
8
|
+
it { is_expected.to be_a(SimpleDelegator) }
|
34
9
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
10
|
+
LOG_LEVELS = %i(debug info warn error fatal unknown).freeze # rubocop:disable Airbnb/SpecConstantAssignment
|
11
|
+
|
12
|
+
context 'without a Logging prefix' do
|
13
|
+
LOG_LEVELS.each do |level|
|
14
|
+
describe "##{level}" do
|
15
|
+
context 'when passed a message string' do
|
16
|
+
it 'passes the message to its wrapped logger' do
|
17
|
+
expect(logger).to receive(level).with('message')
|
18
|
+
wrapper.send(level, 'message')
|
39
19
|
end
|
40
20
|
end
|
41
21
|
|
42
|
-
|
43
|
-
it 'passes the
|
44
|
-
|
45
|
-
|
22
|
+
context 'when passed a message block' do
|
23
|
+
it 'passes the block to its wrapped logger' do
|
24
|
+
block = proc {}
|
25
|
+
expect(logger).to receive(level).with(nil, &block)
|
26
|
+
|
27
|
+
wrapper.send(level, &block)
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'and a progname' do
|
31
|
+
it 'passes the block and progname to its wrapped logger' do
|
32
|
+
block = proc {}
|
33
|
+
expect(logger).to receive(level).with('test', &block)
|
34
|
+
|
35
|
+
wrapper.send(level, 'test', &block)
|
36
|
+
end
|
46
37
|
end
|
47
38
|
end
|
48
39
|
end
|
40
|
+
end
|
49
41
|
|
50
|
-
|
51
|
-
|
42
|
+
describe '#add' do
|
43
|
+
it 'passes the message to its wrapped logger' do
|
44
|
+
expect(logger).to receive(:add).with(Logger::FATAL, 'message', 'progname')
|
45
|
+
wrapper.add(Logger::FATAL, 'message', 'progname')
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
52
49
|
|
53
|
-
|
54
|
-
|
55
|
-
context 'when passed a message string' do
|
56
|
-
it 'passes the prefixed message to its wrapped logger' do
|
57
|
-
expect(logger).to receive(level).with('prefix: message')
|
58
|
-
wrapper.send(level, 'message')
|
59
|
-
end
|
60
|
-
end
|
50
|
+
context 'with a Logging prefix' do
|
51
|
+
before { allow(EXEL::Logging).to receive(:prefix).and_return('prefix: ') }
|
61
52
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
53
|
+
LOG_LEVELS.each do |level|
|
54
|
+
describe "##{level}" do
|
55
|
+
context 'when passed a message string' do
|
56
|
+
it 'passes the prefixed message to its wrapped logger' do
|
57
|
+
expect(logger).to receive(level).with('prefix: message')
|
58
|
+
wrapper.send(level, 'message')
|
59
|
+
end
|
60
|
+
end
|
68
61
|
|
69
|
-
|
70
|
-
|
62
|
+
context 'when passed a message block' do
|
63
|
+
it 'passes the prefixed block to its wrapped logger' do
|
64
|
+
expect(logger).to receive(level) do |progname, &block|
|
65
|
+
expect(progname).to be_nil
|
66
|
+
expect(block.call).to eq('prefix: message')
|
67
|
+
end
|
71
68
|
|
72
|
-
|
73
|
-
|
74
|
-
expect(logger).to receive(level) do |progname, &block|
|
75
|
-
expect(progname).to eq('test')
|
76
|
-
expect(block.call).to eq('prefix: message')
|
77
|
-
end
|
69
|
+
wrapper.send(level) { 'message' }
|
70
|
+
end
|
78
71
|
|
79
|
-
|
80
|
-
|
72
|
+
context 'and a progname' do
|
73
|
+
it 'passes the prefixed block and progname to its wrapped logger' do
|
74
|
+
expect(logger).to receive(level) do |progname, &block|
|
75
|
+
expect(progname).to eq('test')
|
76
|
+
expect(block.call).to eq('prefix: message')
|
81
77
|
end
|
78
|
+
|
79
|
+
wrapper.send(level, 'test') { 'message' }
|
82
80
|
end
|
83
81
|
end
|
84
82
|
end
|
83
|
+
end
|
84
|
+
end
|
85
85
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
end
|
91
|
-
end
|
86
|
+
describe '#add' do
|
87
|
+
it 'passes the prefixed message to its wrapped logger' do
|
88
|
+
expect(logger).to receive(:add).with(Logger::FATAL, 'prefix: message', 'progname')
|
89
|
+
wrapper.add(Logger::FATAL, 'message', 'progname')
|
92
90
|
end
|
93
91
|
end
|
94
92
|
end
|
@@ -1,24 +1,23 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
module EXEL
|
3
|
-
describe LoggingHelper do
|
4
|
-
class HelperClass
|
5
|
-
include LoggingHelper
|
6
|
-
end
|
7
2
|
|
8
|
-
|
3
|
+
describe EXEL::LoggingHelper do
|
4
|
+
class HelperClass
|
5
|
+
include EXEL::LoggingHelper
|
6
|
+
end
|
9
7
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
8
|
+
let(:helper) { HelperClass.new }
|
9
|
+
|
10
|
+
describe '#logger' do
|
11
|
+
it 'returns EXEL.logger' do
|
12
|
+
expect(helper.logger).to eq(EXEL.logger)
|
14
13
|
end
|
14
|
+
end
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
end
|
16
|
+
%i(debug info warn error fatal).each do |level|
|
17
|
+
describe "#log_#{level}" do
|
18
|
+
it "logs a #{level} message" do
|
19
|
+
expect(EXEL.logger).to receive(level).with('test')
|
20
|
+
helper.send("log_#{level}", 'test')
|
22
21
|
end
|
23
22
|
end
|
24
23
|
end
|
data/spec/exel/logging_spec.rb
CHANGED
@@ -1,80 +1,80 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
2
|
+
|
3
|
+
describe EXEL::Logging do
|
4
|
+
before { @restore_logger = EXEL::Logging.logger }
|
5
|
+
|
6
|
+
after { EXEL::Logging.logger = @restore_logger }
|
7
|
+
|
8
|
+
describe EXEL::Logging::PrefixFormatter do
|
9
|
+
context 'without a Logging prefix' do
|
10
|
+
it 'formats the message' do
|
11
|
+
expect(subject.call('warn', Time.new(2007, 11, 1, 15, 25, 0, '+09:00'), 'test', 'message'))
|
12
|
+
.to eq("2007-11-01 06:25:00 UTC severity=warn, message\n")
|
13
13
|
end
|
14
|
+
end
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
16
|
+
context 'with a Logging prefix' do
|
17
|
+
it 'adds the prefix to the formatted message' do
|
18
|
+
EXEL::Logging.with_prefix('[prefix] ') do
|
19
|
+
expect(subject.call('warn', Time.new(2007, 11, 1, 15, 25, 0, '+09:00'), 'test', 'message'))
|
20
|
+
.to eq("2007-11-01 06:25:00 UTC severity=warn, [prefix] message\n")
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
24
|
+
end
|
24
25
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
26
|
+
describe '.logger=' do
|
27
|
+
it 'sets a wrapped logger' do
|
28
|
+
logger = instance_double(Logger)
|
29
|
+
EXEL::Logging.logger = logger
|
30
|
+
expect(EXEL::Logging.logger).to be_a(EXEL::Logging::LoggerWrapper)
|
31
|
+
expect(EXEL::Logging.logger.__getobj__).to be(logger)
|
32
|
+
end
|
32
33
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
end
|
34
|
+
it 'sets a null logger when nil given' do
|
35
|
+
expect(Logger).to receive(:new).with('/dev/null')
|
36
|
+
EXEL::Logging.logger = nil
|
37
37
|
end
|
38
|
+
end
|
38
39
|
|
39
|
-
|
40
|
-
|
40
|
+
describe '.logger' do
|
41
|
+
before { EXEL::Logging.instance_variable_set(:@logger, nil) }
|
41
42
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
43
|
+
it 'initializes the logger on first read if not already set' do
|
44
|
+
EXEL.configure do |config|
|
45
|
+
config.log_level = :warn
|
46
|
+
config.log_filename = 'log.txt'
|
47
|
+
end
|
47
48
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
49
|
+
logger = instance_double(Logger)
|
50
|
+
expect(Logger).to receive(:new).with('log.txt').and_return(logger)
|
51
|
+
expect(logger).to receive(:level=).with(Logger::WARN)
|
52
|
+
expect(logger).to receive(:formatter=).with(EXEL::Logging::PrefixFormatter)
|
52
53
|
|
53
|
-
|
54
|
-
end
|
54
|
+
EXEL::Logging.logger
|
55
55
|
end
|
56
|
+
end
|
56
57
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
Logging.with_prefix('testing') do
|
62
|
-
expect(Logging.prefix).to eq('testing')
|
63
|
-
end
|
58
|
+
describe '.with_prefix' do
|
59
|
+
it 'sets the prefix before yielding to the block and clears it after' do
|
60
|
+
expect(EXEL::Logging.prefix).to be_nil
|
64
61
|
|
65
|
-
|
62
|
+
EXEL::Logging.with_prefix('testing') do
|
63
|
+
expect(EXEL::Logging.prefix).to eq('testing')
|
66
64
|
end
|
67
65
|
|
68
|
-
|
69
|
-
|
70
|
-
expect(Logging.prefix).to eq('outer')
|
66
|
+
expect(EXEL::Logging.prefix).to be_nil
|
67
|
+
end
|
71
68
|
|
72
|
-
|
73
|
-
|
74
|
-
|
69
|
+
it 'handles nesting' do
|
70
|
+
EXEL::Logging.with_prefix('outer') do
|
71
|
+
expect(EXEL::Logging.prefix).to eq('outer')
|
75
72
|
|
76
|
-
|
73
|
+
EXEL::Logging.with_prefix('inner') do
|
74
|
+
expect(EXEL::Logging.prefix).to eq('inner')
|
77
75
|
end
|
76
|
+
|
77
|
+
expect(EXEL::Logging.prefix).to eq('outer')
|
78
78
|
end
|
79
79
|
end
|
80
80
|
end
|
@@ -1,67 +1,65 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
module EXEL
|
3
|
-
module Middleware
|
4
|
-
describe Chain do
|
5
|
-
subject(:chain) { EXEL::Middleware::Chain.new }
|
6
2
|
|
7
|
-
|
8
|
-
|
9
|
-
end
|
3
|
+
describe EXEL::Middleware::Chain do
|
4
|
+
subject(:chain) { EXEL::Middleware::Chain.new }
|
10
5
|
|
11
|
-
|
12
|
-
|
13
|
-
|
6
|
+
class TestMiddleware
|
7
|
+
def initialize(*)
|
8
|
+
end
|
14
9
|
|
15
|
-
|
10
|
+
def call
|
11
|
+
end
|
12
|
+
end
|
16
13
|
|
17
|
-
|
18
|
-
|
19
|
-
chain.add(TestMiddleware)
|
20
|
-
expect(chain).to include(TestMiddleware)
|
21
|
-
end
|
14
|
+
class AnotherTestMiddleware < TestMiddleware
|
15
|
+
end
|
22
16
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
17
|
+
describe '#add' do
|
18
|
+
it 'adds a middleware to the chain' do
|
19
|
+
chain.add(TestMiddleware)
|
20
|
+
expect(chain).to include(TestMiddleware)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'removes and adds to end if already present' do
|
24
|
+
chain.add(TestMiddleware)
|
25
|
+
chain.add(AnotherTestMiddleware)
|
26
|
+
chain.add(TestMiddleware)
|
27
|
+
expect(chain.entries.map(&:klass)).to eq([AnotherTestMiddleware, TestMiddleware])
|
28
|
+
end
|
29
|
+
end
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
31
|
+
describe '#remove' do
|
32
|
+
it 'removes a middleware from the chain' do
|
33
|
+
chain.add(TestMiddleware)
|
34
|
+
chain.add(AnotherTestMiddleware)
|
35
|
+
chain.remove(TestMiddleware)
|
36
|
+
expect(chain.entries.map(&:klass)).to eq([AnotherTestMiddleware])
|
37
|
+
end
|
38
|
+
end
|
39
39
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
40
|
+
describe '#include?' do
|
41
|
+
it 'returns true if the middleware class is in the chain' do
|
42
|
+
chain.add(TestMiddleware)
|
43
|
+
expect(chain).to include(TestMiddleware)
|
44
|
+
end
|
45
45
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
46
|
+
it 'returns false if the middleware class is not in the chain' do
|
47
|
+
chain.add(TestMiddleware)
|
48
|
+
expect(chain).not_to include(AnotherTestMiddleware)
|
49
|
+
end
|
50
|
+
end
|
51
51
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
52
|
+
describe '#invoke' do
|
53
|
+
it 'calls each middleware' do
|
54
|
+
chain.add(TestMiddleware)
|
55
|
+
expect_any_instance_of(TestMiddleware).to receive(:call).with(1, 2, 3)
|
56
|
+
chain.invoke(1, 2, 3)
|
57
|
+
end
|
58
58
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
end
|
64
|
-
end
|
59
|
+
it 'initializes middleware with given constructor arguments' do
|
60
|
+
chain.add(TestMiddleware, 1, 2)
|
61
|
+
expect(TestMiddleware).to receive(:new).with(1, 2).and_return(TestMiddleware.new)
|
62
|
+
chain.invoke
|
65
63
|
end
|
66
64
|
end
|
67
65
|
end
|