exel 1.4.0 → 1.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +5 -5
  2. data/.codeclimate.yml +4 -4
  3. data/.rubocop.yml +20 -12
  4. data/.rubocop_airbnb.yml +2 -0
  5. data/.travis.yml +17 -4
  6. data/Gemfile +1 -2
  7. data/Gemfile.lock +64 -60
  8. data/README.md +1 -1
  9. data/Rakefile +1 -0
  10. data/exel.gemspec +4 -4
  11. data/lib/exel.rb +1 -0
  12. data/lib/exel/ast_node.rb +2 -1
  13. data/lib/exel/context.rb +2 -1
  14. data/lib/exel/deferred_context_value.rb +1 -0
  15. data/lib/exel/error/job_termination.rb +1 -0
  16. data/lib/exel/events.rb +1 -0
  17. data/lib/exel/instruction.rb +2 -1
  18. data/lib/exel/instruction_node.rb +1 -0
  19. data/lib/exel/job.rb +6 -4
  20. data/lib/exel/listen_instruction.rb +1 -0
  21. data/lib/exel/logging.rb +1 -0
  22. data/lib/exel/logging/logger_wrapper.rb +4 -1
  23. data/lib/exel/logging_helper.rb +1 -0
  24. data/lib/exel/middleware/chain.rb +1 -0
  25. data/lib/exel/middleware/logging.rb +1 -1
  26. data/lib/exel/null_instruction.rb +1 -0
  27. data/lib/exel/processor_helper.rb +1 -0
  28. data/lib/exel/processors/run_processor.rb +1 -0
  29. data/lib/exel/processors/split_processor.rb +2 -1
  30. data/lib/exel/providers/local_file_provider.rb +2 -1
  31. data/lib/exel/providers/threaded_async_provider.rb +1 -0
  32. data/lib/exel/sequence_node.rb +1 -0
  33. data/lib/exel/value.rb +1 -0
  34. data/lib/exel/version.rb +2 -1
  35. data/spec/exel/ast_node_spec.rb +42 -42
  36. data/spec/exel/context_spec.rb +76 -77
  37. data/spec/exel/deferred_context_value_spec.rb +41 -42
  38. data/spec/exel/events_spec.rb +65 -65
  39. data/spec/exel/instruction_node_spec.rb +16 -16
  40. data/spec/exel/instruction_spec.rb +46 -45
  41. data/spec/exel/job_spec.rb +94 -91
  42. data/spec/exel/listen_instruction_spec.rb +10 -10
  43. data/spec/exel/logging/logger_wrapper_spec.rb +67 -69
  44. data/spec/exel/logging_helper_spec.rb +15 -16
  45. data/spec/exel/logging_spec.rb +56 -56
  46. data/spec/exel/middleware/chain_spec.rb +51 -53
  47. data/spec/exel/middleware/logging_spec.rb +21 -23
  48. data/spec/exel/middleware_spec.rb +49 -50
  49. data/spec/exel/null_instruction_spec.rb +3 -4
  50. data/spec/exel/processors/async_processor_spec.rb +16 -18
  51. data/spec/exel/processors/run_processor_spec.rb +9 -11
  52. data/spec/exel/processors/split_processor_spec.rb +91 -93
  53. data/spec/exel/providers/local_file_provider_spec.rb +25 -28
  54. data/spec/exel/providers/threaded_async_provider_spec.rb +36 -38
  55. data/spec/exel/sequence_node_spec.rb +11 -11
  56. data/spec/exel/value_spec.rb +32 -33
  57. data/spec/exel_spec.rb +8 -7
  58. data/spec/integration/integration_spec.rb +2 -1
  59. data/spec/spec_helper.rb +3 -2
  60. data/spec/support/integration_test_classes.rb +3 -1
  61. 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
- describe '#execute' do
9
- it 'registers the event listener' do
10
- expect(instruction).to receive(:register_listener).with(context, :event, listener)
11
- instruction.execute(context)
12
- end
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
- 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)
3
+ describe EXEL::Logging::LoggerWrapper do
4
+ subject(:wrapper) { EXEL::Logging::LoggerWrapper.new(logger) }
26
5
 
27
- wrapper.send(level, &block)
28
- end
6
+ let(:logger) { instance_double(Logger) }
29
7
 
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)
8
+ it { is_expected.to be_a(SimpleDelegator) }
34
9
 
35
- wrapper.send(level, 'test', &block)
36
- end
37
- end
38
- end
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
- 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')
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
- context 'with a Logging prefix' do
51
- before { allow(Logging).to receive(:prefix).and_return('prefix: ') }
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
- 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
50
+ context 'with a Logging prefix' do
51
+ before { allow(EXEL::Logging).to receive(:prefix).and_return('prefix: ') }
61
52
 
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
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
- wrapper.send(level) { 'message' }
70
- end
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
- 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')
77
- end
69
+ wrapper.send(level) { 'message' }
70
+ end
78
71
 
79
- wrapper.send(level, 'test') { 'message' }
80
- end
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
- 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')
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
- let(:helper) { HelperClass.new }
3
+ describe EXEL::LoggingHelper do
4
+ class HelperClass
5
+ include EXEL::LoggingHelper
6
+ end
9
7
 
10
- describe '#logger' do
11
- it 'returns EXEL.logger' do
12
- expect(helper.logger).to eq(EXEL.logger)
13
- end
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
- %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')
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
@@ -1,80 +1,80 @@
1
1
  # frozen_string_literal: true
2
- module EXEL
3
- describe Logging do
4
- before { @restore_logger = Logging.logger }
5
- after { Logging.logger = @restore_logger }
6
-
7
- describe Logging::PrefixFormatter do
8
- context 'without a Logging prefix' do
9
- it 'formats the message' do
10
- expect(subject.call('warn', Time.new(2007, 11, 1, 15, 25, 0, '+09:00'), 'test', 'message'))
11
- .to eq("2007-11-01 06:25:00 UTC severity=warn, message\n")
12
- end
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
- context 'with a Logging prefix' do
16
- it 'adds the prefix to the formatted message' do
17
- Logging.with_prefix('[prefix] ') do
18
- expect(subject.call('warn', Time.new(2007, 11, 1, 15, 25, 0, '+09:00'), 'test', 'message'))
19
- .to eq("2007-11-01 06:25:00 UTC severity=warn, [prefix] message\n")
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
- describe '.logger=' do
26
- it 'sets a wrapped logger' do
27
- logger = instance_double(Logger)
28
- Logging.logger = logger
29
- expect(Logging.logger).to be_a(Logging::LoggerWrapper)
30
- expect(Logging.logger.__getobj__).to be(logger)
31
- end
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
- it 'sets a null logger when nil given' do
34
- expect(Logger).to receive(:new).with('/dev/null')
35
- Logging.logger = nil
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
- describe '.logger' do
40
- before { Logging.instance_variable_set(:@logger, nil) }
40
+ describe '.logger' do
41
+ before { EXEL::Logging.instance_variable_set(:@logger, nil) }
41
42
 
42
- it 'initializes the logger on first read if not already set' do
43
- EXEL.configure do |config|
44
- config.log_level = :warn
45
- config.log_filename = 'log.txt'
46
- end
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
- logger = instance_double(Logger)
49
- expect(Logger).to receive(:new).with('log.txt').and_return(logger)
50
- expect(logger).to receive(:level=).with(Logger::WARN)
51
- expect(logger).to receive(:formatter=).with(Logging::PrefixFormatter)
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
- Logging.logger
54
- end
54
+ EXEL::Logging.logger
55
55
  end
56
+ end
56
57
 
57
- describe '.with_prefix' do
58
- it 'sets the prefix before yielding to the block and clears it after' do
59
- expect(Logging.prefix).to be_nil
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
- expect(Logging.prefix).to be_nil
62
+ EXEL::Logging.with_prefix('testing') do
63
+ expect(EXEL::Logging.prefix).to eq('testing')
66
64
  end
67
65
 
68
- it 'handles nesting' do
69
- Logging.with_prefix('outer') do
70
- expect(Logging.prefix).to eq('outer')
66
+ expect(EXEL::Logging.prefix).to be_nil
67
+ end
71
68
 
72
- Logging.with_prefix('inner') do
73
- expect(Logging.prefix).to eq('inner')
74
- end
69
+ it 'handles nesting' do
70
+ EXEL::Logging.with_prefix('outer') do
71
+ expect(EXEL::Logging.prefix).to eq('outer')
75
72
 
76
- expect(Logging.prefix).to eq('outer')
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
- class TestMiddleware
8
- def initialize(*)
9
- end
3
+ describe EXEL::Middleware::Chain do
4
+ subject(:chain) { EXEL::Middleware::Chain.new }
10
5
 
11
- def call
12
- end
13
- end
6
+ class TestMiddleware
7
+ def initialize(*)
8
+ end
14
9
 
15
- AnotherTestMiddleware = Class.new(TestMiddleware)
10
+ def call
11
+ end
12
+ end
16
13
 
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
14
+ class AnotherTestMiddleware < TestMiddleware
15
+ end
22
16
 
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
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
- 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
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
- 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
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
- 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
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
- 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
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
- 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
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