producer-core 0.5.8 → 0.5.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. checksums.yaml +4 -4
  2. data/lib/producer/core/version.rb +1 -1
  3. metadata +21 -202
  4. data/.gitignore +0 -3
  5. data/.travis.yml +0 -14
  6. data/Gemfile +0 -5
  7. data/Guardfile +0 -14
  8. data/LICENSE +0 -30
  9. data/Rakefile +0 -19
  10. data/config/cucumber.yaml +0 -2
  11. data/features/actions/echo.feature +0 -11
  12. data/features/actions/file_append.feature +0 -15
  13. data/features/actions/file_replace_content.feature +0 -24
  14. data/features/actions/file_write.feature +0 -21
  15. data/features/actions/mkdir.feature +0 -31
  16. data/features/actions/sh.feature +0 -43
  17. data/features/actions/yaml_write.feature +0 -14
  18. data/features/cli/debug.feature +0 -19
  19. data/features/cli/dry_run.feature +0 -22
  20. data/features/cli/error_reporting.feature +0 -32
  21. data/features/cli/target.feature +0 -15
  22. data/features/cli/usage.feature +0 -13
  23. data/features/cli/verbose.feature +0 -48
  24. data/features/condition/negated_test.feature +0 -47
  25. data/features/condition/target.feature +0 -15
  26. data/features/recipe/compose_macro.feature +0 -29
  27. data/features/recipe/errors.feature +0 -9
  28. data/features/recipe/macro.feature +0 -50
  29. data/features/recipe/registry.feature +0 -82
  30. data/features/recipe/source.feature +0 -17
  31. data/features/recipe/target.feature +0 -23
  32. data/features/recipe/test_macro.feature +0 -50
  33. data/features/ssh/config.feature +0 -25
  34. data/features/steps/environment_steps.rb +0 -3
  35. data/features/support/env.rb +0 -1
  36. data/features/task/ask.feature +0 -23
  37. data/features/task/condition.feature +0 -13
  38. data/features/task/nested_tasks.feature +0 -20
  39. data/features/task/recipe_argv.feature +0 -13
  40. data/features/task/target.feature +0 -11
  41. data/features/task/template.feature +0 -49
  42. data/features/tests/dir.feature +0 -21
  43. data/features/tests/env.feature +0 -47
  44. data/features/tests/executable.feature +0 -26
  45. data/features/tests/file.feature +0 -21
  46. data/features/tests/file_contains.feature +0 -26
  47. data/features/tests/file_eq.feature +0 -26
  48. data/features/tests/file_match.feature +0 -26
  49. data/features/tests/shell_command_status.feature +0 -46
  50. data/features/tests/yaml_eq.feature +0 -26
  51. data/producer-core.gemspec +0 -28
  52. data/spec/fixtures/recipes/empty.rb +0 -1
  53. data/spec/fixtures/recipes/raise.rb +0 -1
  54. data/spec/fixtures/recipes/some_recipe.rb +0 -5
  55. data/spec/fixtures/recipes/throw.rb +0 -1
  56. data/spec/fixtures/templates/basic.erb +0 -1
  57. data/spec/fixtures/templates/basic_yaml.yaml +0 -1
  58. data/spec/fixtures/templates/variables.erb +0 -1
  59. data/spec/producer/core/action_spec.rb +0 -46
  60. data/spec/producer/core/actions/echo_spec.rb +0 -20
  61. data/spec/producer/core/actions/file_append_spec.rb +0 -49
  62. data/spec/producer/core/actions/file_replace_content_spec.rb +0 -42
  63. data/spec/producer/core/actions/file_writer_spec.rb +0 -52
  64. data/spec/producer/core/actions/mkdir_spec.rb +0 -71
  65. data/spec/producer/core/actions/shell_command_spec.rb +0 -45
  66. data/spec/producer/core/actions/yaml_writer_spec.rb +0 -25
  67. data/spec/producer/core/cli_spec.rb +0 -211
  68. data/spec/producer/core/condition_spec.rb +0 -198
  69. data/spec/producer/core/env_spec.rb +0 -196
  70. data/spec/producer/core/error_formatter_spec.rb +0 -86
  71. data/spec/producer/core/logger_formatter_spec.rb +0 -26
  72. data/spec/producer/core/prompter_spec.rb +0 -40
  73. data/spec/producer/core/recipe/file_evaluator_spec.rb +0 -22
  74. data/spec/producer/core/recipe_spec.rb +0 -126
  75. data/spec/producer/core/remote/environment_spec.rb +0 -19
  76. data/spec/producer/core/remote/fs_spec.rb +0 -144
  77. data/spec/producer/core/remote_spec.rb +0 -168
  78. data/spec/producer/core/task_spec.rb +0 -198
  79. data/spec/producer/core/template_spec.rb +0 -41
  80. data/spec/producer/core/test_spec.rb +0 -7
  81. data/spec/producer/core/testing/mock_remote_spec.rb +0 -66
  82. data/spec/producer/core/tests/condition_test_spec.rb +0 -55
  83. data/spec/producer/core/tests/file_contains_spec.rb +0 -46
  84. data/spec/producer/core/tests/file_eq_spec.rb +0 -45
  85. data/spec/producer/core/tests/file_match_spec.rb +0 -46
  86. data/spec/producer/core/tests/has_dir_spec.rb +0 -25
  87. data/spec/producer/core/tests/has_env_spec.rb +0 -75
  88. data/spec/producer/core/tests/has_executable_spec.rb +0 -29
  89. data/spec/producer/core/tests/has_file_spec.rb +0 -25
  90. data/spec/producer/core/tests/shell_command_status_spec.rb +0 -34
  91. data/spec/producer/core/tests/yaml_eq_spec.rb +0 -47
  92. data/spec/producer/core/worker_spec.rb +0 -88
  93. data/spec/spec_helper.rb +0 -13
  94. data/spec/support/exit_helpers.rb +0 -6
  95. data/spec/support/fixtures_helpers.rb +0 -7
  96. data/spec/support/net_ssh_story_helpers.rb +0 -36
  97. data/spec/support/shared_action.rb +0 -44
  98. data/spec/support/shared_test.rb +0 -82
  99. data/spec/support/test_env_helpers.rb +0 -44
@@ -1,211 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Producer::Core
4
- describe CLI do
5
- include ExitHelpers
6
- include FixturesHelpers
7
-
8
- let(:options) { [] }
9
- let(:recipe_file) { fixture_path_for 'recipes/some_recipe.rb' }
10
- let(:arguments) { [*options, recipe_file] }
11
- let(:environment) { {} }
12
-
13
- subject(:cli) { described_class.new(arguments, environment) }
14
-
15
- describe '.run!' do
16
- subject(:run!) { described_class.run! arguments }
17
-
18
- it 'builds a new CLI instance with given arguments and environment' do
19
- expect(described_class)
20
- .to receive(:new).with(arguments, ENV, anything).and_call_original
21
- run!
22
- end
23
-
24
- it 'parses new CLI instance arguments' do
25
- expect_any_instance_of(described_class).to receive :parse_arguments!
26
- run!
27
- end
28
-
29
- it 'runs the new CLI instance' do
30
- expect_any_instance_of(described_class).to receive :run
31
- run!
32
- end
33
-
34
- context 'when no recipe is given' do
35
- let(:arguments) { [] }
36
-
37
- it 'exits with a return status of 64' do
38
- expect { described_class.run! arguments, stderr: StringIO.new }
39
- .to raise_error(SystemExit) { |e| expect(e.status).to eq 64 }
40
- end
41
-
42
- it 'prints the usage on the error stream' do
43
- expect { trap_exit { run! } }
44
- .to output(/\AUsage: .+/).to_stderr
45
- end
46
- end
47
-
48
- context 'when an error is raised' do
49
- let(:recipe_file) { fixture_path_for 'recipes/raise.rb' }
50
-
51
- it 'exits with a return status of 70' do
52
- expect { described_class.run! arguments, stderr: StringIO.new }
53
- .to raise_error(SystemExit) { |e| expect(e.status).to eq 70 }
54
- end
55
-
56
- it 'prints a report to the error stream' do
57
- expect { trap_exit { run! } }
58
- .to output(/\ARecipeEvaluationError: false$/).to_stderr
59
- end
60
- end
61
- end
62
-
63
- describe '#initialize' do
64
- it 'assigns an env' do
65
- expect(cli.env).to be_an Env
66
- end
67
-
68
- it 'assigns CLI stdin as the env input' do
69
- expect(cli.env.input).to be cli.stdin
70
- end
71
-
72
- it 'assigns CLI stdout as the env output' do
73
- expect(cli.env.output).to be cli.stdout
74
- end
75
-
76
- it 'assigns CLI stderr as the env error output' do
77
- expect(cli.env.error_output).to be cli.stderr
78
- end
79
-
80
- context 'when PRODUCER_VERBOSE environment variable is set' do
81
- before { environment['PRODUCER_VERBOSE'] = 'yes' }
82
-
83
- it 'enables env verbose mode' do
84
- expect(cli.env).to be_verbose
85
- end
86
- end
87
-
88
- context 'when PRODUCER_DEBUG environment variable is set' do
89
- before { environment['PRODUCER_DEBUG'] = 'yes' }
90
-
91
- it 'enables env debug mode' do
92
- expect(cli.env).to be_debug
93
- end
94
- end
95
-
96
- context 'when PRODUCER_DRYRUN environment variable is set' do
97
- before { environment['PRODUCER_DRYRUN'] = 'yes' }
98
-
99
- it 'enables env dry run mode' do
100
- expect(cli.env).to be_dry_run
101
- end
102
- end
103
- end
104
-
105
- describe '#parse_arguments!' do
106
- let(:options) { %w[-v -t some_host.example] }
107
-
108
- it 'removes options from arguments' do
109
- cli.parse_arguments!
110
- expect(cli.arguments).to eq [recipe_file]
111
- end
112
-
113
- context 'with verbose option' do
114
- let(:options) { %w[-v] }
115
-
116
- it 'enables env verbose mode' do
117
- cli.parse_arguments!
118
- expect(cli.env).to be_verbose
119
- end
120
- end
121
-
122
- context 'with dry run option' do
123
- let(:options) { %w[-n] }
124
-
125
- it 'enables env dry run mode' do
126
- cli.parse_arguments!
127
- expect(cli.env).to be_dry_run
128
- end
129
- end
130
-
131
- context 'with target option' do
132
- let(:options) { %w[-t some_host.example] }
133
-
134
- it 'assigns the given target to the env' do
135
- cli.parse_arguments!
136
- expect(cli.env.target).to eq 'some_host.example'
137
- end
138
- end
139
-
140
- context 'with debug option' do
141
- let(:options) { %w[-d] }
142
-
143
- it 'assigns the given target to the env' do
144
- cli.parse_arguments!
145
- expect(cli.env).to be_debug
146
- end
147
- end
148
-
149
- context 'with combined options' do
150
- let(:options) { %w[-vn]}
151
-
152
- it 'handles combined options' do
153
- cli.parse_arguments!
154
- expect(cli.env).to be_verbose.and be_dry_run
155
- end
156
- end
157
-
158
- context 'with recipe arguments' do
159
- let(:arguments) { %w[recipe.rb -- foo] }
160
-
161
- it 'removes recipe arguments' do
162
- cli.parse_arguments!
163
- expect(cli.arguments).to eq %w[recipe.rb]
164
- end
165
-
166
- it 'assigns env recipe arguments' do
167
- cli.parse_arguments!
168
- expect(cli.env.recipe_argv).to eq %w[foo]
169
- end
170
- end
171
-
172
- context 'when no arguments remains after parsing' do
173
- let(:arguments) { [] }
174
-
175
- it 'raises an error' do
176
- expect { cli.parse_arguments! }
177
- .to raise_error described_class::ArgumentError
178
- end
179
- end
180
- end
181
-
182
- describe '#run' do
183
- it 'processes recipes tasks with a worker' do
184
- worker = instance_spy Worker
185
- cli.run worker: worker
186
- expect(worker).to have_received(:process)
187
- .with all be_an_instance_of Task
188
- end
189
-
190
- it 'cleans up the env' do
191
- expect(cli.env).to receive :cleanup
192
- cli.run
193
- end
194
-
195
- context 'on error' do
196
- let(:recipe_file) { fixture_path_for 'recipes/raise.rb' }
197
-
198
- it 'cleans up the env' do
199
- expect(cli.env).to receive :cleanup
200
- cli.run rescue nil
201
- end
202
- end
203
- end
204
-
205
- describe '#evaluate_recipes' do
206
- it 'returns the evaluated recipes' do
207
- expect(cli.evaluate_recipes).to all be_an_instance_of Recipe
208
- end
209
- end
210
- end
211
- end
@@ -1,198 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Producer::Core
4
- describe Condition do
5
- subject(:condition) { described_class.new }
6
-
7
- %w[
8
- `
9
- sh
10
- file_contains
11
- file_eq
12
- file_match
13
- dir?
14
- env?
15
- executable?
16
- file?
17
- ].each do |test|
18
- it "has `#{test}' test defined" do
19
- expect(condition).to respond_to test.to_sym
20
- end
21
- end
22
-
23
- describe '.define_test' do
24
- let(:some_test) { Test }
25
-
26
- before { described_class.define_test(:some_test, some_test) }
27
-
28
- it 'defines a new test keyword' do
29
- expect(condition).to respond_to :some_test
30
- end
31
-
32
- it 'defines the negated test' do
33
- expect(condition).to respond_to :no_some_test
34
- end
35
-
36
- context 'when a test keyword is called' do
37
- it 'registers the test' do
38
- expect { condition.some_test }.to change { condition.tests.count }.by 1
39
- end
40
-
41
- it 'registers the test with assigned env' do
42
- env = double 'env'
43
- condition.instance_eval { @env = env }
44
- condition.some_test
45
- expect(condition.tests.last.env).to be env
46
- end
47
-
48
- it 'registers the test with given arguments' do
49
- condition.some_test :foo, :bar
50
- expect(condition.tests.last.arguments).to eq %i[foo bar]
51
- end
52
-
53
- context 'when given test is callable' do
54
- let(:some_test) { proc { } }
55
-
56
- before { condition.some_test }
57
-
58
- it 'registers a condition test' do
59
- expect(condition.tests.last).to be_a Tests::ConditionTest
60
- end
61
-
62
- it 'registers the test with given block' do
63
- expect(condition.tests.last.condition_block).to be some_test
64
- end
65
-
66
- it 'registers the test with given arguments' do
67
- condition.some_test :foo, :bar
68
- expect(condition.tests.last.condition_args).to eq %i[foo bar]
69
- end
70
- end
71
- end
72
-
73
- context 'when a negated test keyword is called' do
74
- it 'registers a negated test' do
75
- condition.no_some_test
76
- expect(condition.tests.last).to be_negated
77
- end
78
- end
79
- end
80
-
81
- describe '.evaluate' do
82
- let(:env) { double 'env' }
83
- let(:code) { proc { some_test; :some_return_value } }
84
- let(:some_test) { Class.new(Test) }
85
- let(:arguments) { [] }
86
- subject(:condition) { described_class.evaluate(env, *arguments, &code) }
87
-
88
- before { described_class.define_test(:some_test, some_test) }
89
-
90
- it 'returns an evaluated condition' do
91
- expect(condition).to be_a described_class
92
- end
93
-
94
- it 'evaluates the condition tests' do
95
- expect(condition.tests.first).to be_a Test
96
- end
97
-
98
- it 'evaluates the condition return value' do
99
- expect(condition.return_value).to eq :some_return_value
100
- end
101
-
102
- context 'when arguments are given' do
103
- let(:code) { proc { |a, b| throw a } }
104
- let(:arguments) { %i[foo bar] }
105
-
106
- it 'passes arguments as block parameters' do
107
- expect { condition }
108
- .to throw_symbol :foo
109
- end
110
- end
111
- end
112
-
113
- describe '#initialize' do
114
- it 'assigns no tests' do
115
- expect(condition.tests).to be_empty
116
- end
117
-
118
- it 'assigns the return value as nil' do
119
- expect(condition.return_value).to be nil
120
- end
121
- end
122
-
123
- describe '#met?' do
124
- let(:test_ok) { instance_spy Test, pass?: true }
125
- let(:test_ko) { instance_spy Test, pass?: false }
126
- subject(:condition) { described_class.new(tests) }
127
-
128
- context 'when all tests are successful' do
129
- let(:tests) { [test_ok, test_ok] }
130
-
131
- it 'returns true' do
132
- expect(condition.met?).to be true
133
- end
134
- end
135
-
136
- context 'when one test is unsuccessful' do
137
- let(:tests) { [test_ok, test_ko] }
138
-
139
- it 'returns false' do
140
- expect(condition.met?).to be false
141
- end
142
- end
143
-
144
- context 'when there are no test' do
145
- let(:tests) { [] }
146
- subject(:condition) { described_class.new([], return_value) }
147
-
148
- context 'and return value is truthy' do
149
- let(:return_value) { :some_truthy_value }
150
-
151
- it 'returns true' do
152
- expect(condition.met?).to be true
153
- end
154
- end
155
-
156
- context 'and return value is falsy' do
157
- let(:return_value) { nil }
158
-
159
- it 'returns false' do
160
- expect(condition.met?).to be false
161
- end
162
- end
163
- end
164
- end
165
-
166
- describe '#!' do
167
- [true, false].each do |b|
168
- context "when #met? return #{b}" do
169
- before { allow(condition).to receive(:met?) { b } }
170
-
171
- it 'returns the negated #met?' do
172
- expect(condition.!).to be !condition.met?
173
- end
174
- end
175
- end
176
- end
177
-
178
- describe '#get' do
179
- let(:env) { Env.new }
180
-
181
- it 'delegates to env registry' do
182
- expect(env).to receive(:get).with :some_key
183
- described_class.evaluate(env, []) { get :some_key }
184
- end
185
- end
186
-
187
- describe '#target' do
188
- let(:env) { Env.new }
189
-
190
- before { env.target = :some_target }
191
-
192
- it 'returns current env target' do
193
- condition = described_class.evaluate(env, []) { target == :some_target }
194
- expect(condition).to be_met
195
- end
196
- end
197
- end
198
- end
@@ -1,196 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Producer::Core
4
- describe Env do
5
- let(:output) { StringIO.new }
6
- subject(:env) { described_class.new(output: output) }
7
-
8
- describe '#initialize' do
9
- it 'assigns $stdin as the default input' do
10
- expect(env.input).to be $stdin
11
- end
12
-
13
- it 'assigns $stderr as the default error output' do
14
- expect(env.error_output).to be $stderr
15
- end
16
-
17
- it 'assigns no default target' do
18
- expect(env.target).not_to be
19
- end
20
-
21
- it 'assigns an empty registry' do
22
- expect(env.registry).to be_empty
23
- end
24
-
25
- it 'assigns verbose as false' do
26
- expect(env.verbose).to be false
27
- end
28
-
29
- it 'assigns debug as false' do
30
- expect(env.debug).to be false
31
- end
32
-
33
- it 'assigns dry run as false' do
34
- expect(env.dry_run).to be false
35
- end
36
-
37
- context 'when output is not given as argument' do
38
- subject(:env) { described_class.new }
39
-
40
- it 'assigns $stdout as the default output' do
41
- expect(env.output).to be $stdout
42
- end
43
- end
44
-
45
- context 'when input is given as argument' do
46
- let(:input) { double 'input' }
47
- subject(:env) { described_class.new(input: input) }
48
-
49
- it 'assigns the given input' do
50
- expect(env.input).to be input
51
- end
52
- end
53
-
54
- context 'when output is given as argument' do
55
- subject(:env) { described_class.new(output: output) }
56
-
57
- it 'assigns the given output' do
58
- expect(env.output).to be output
59
- end
60
- end
61
-
62
- context 'when error output is given as argument' do
63
- let(:error_output) { StringIO.new }
64
- subject(:env) { described_class.new(error_output: error_output) }
65
-
66
- it 'assigns the given error output' do
67
- expect(env.error_output).to be error_output
68
- end
69
- end
70
-
71
- context 'when remote is given as argument' do
72
- let(:remote) { double 'remote' }
73
- subject(:env) { described_class.new(remote: remote) }
74
-
75
- it 'assigns the given remote' do
76
- expect(env.remote).to be remote
77
- end
78
- end
79
- end
80
-
81
- describe '#target' do
82
- let(:target) { double 'target' }
83
-
84
- it 'returns the assigned target' do
85
- env.target = target
86
- expect(env.target).to be target
87
- end
88
- end
89
-
90
- describe '#remote' do
91
- it 'builds a Remote with the current target' do
92
- env.target = 'some_hostname.example'
93
- expect(Remote).to receive(:new).with(env.target)
94
- env.remote
95
- end
96
-
97
- it 'returns the remote' do
98
- remote = double 'remote'
99
- allow(Remote).to receive(:new) { remote }
100
- expect(env.remote).to eq remote
101
- end
102
-
103
- it 'memoizes the remote' do
104
- expect(env.remote).to be env.remote
105
- end
106
- end
107
-
108
- describe '#[]' do
109
- subject(:env) { Env.new(registry: { some_key: :some_value }) }
110
-
111
- it 'returns the value indexed by given key from the registry' do
112
- expect(env[:some_key]).to eq :some_value
113
- end
114
-
115
- it 'raises an error when given invalid key' do
116
- expect { env[:no_key] }.to raise_error RegistryKeyError
117
- end
118
- end
119
-
120
- describe '#[]=' do
121
- it 'registers given value at given index in the registry' do
122
- env[:some_key] = :some_value
123
- expect(env[:some_key]).to eq :some_value
124
- end
125
- end
126
-
127
- describe '#logger' do
128
- it 'returns a logger' do
129
- expect(env.logger).to be_a Logger
130
- end
131
-
132
- it 'uses env output' do
133
- env.logger.error 'some message'
134
- expect(output.string).to include 'some message'
135
- end
136
-
137
- it 'has a log level of WARN' do
138
- expect(env.logger.level).to eq Logger::WARN
139
- end
140
-
141
- it 'uses our formatter' do
142
- expect(env.logger.formatter).to be_a LoggerFormatter
143
- end
144
-
145
- context 'when verbose mode is enabled' do
146
- before { env.verbose = true }
147
-
148
- it 'has a log level of INFO' do
149
- expect(env.logger.level).to eq Logger::INFO
150
- end
151
- end
152
- end
153
-
154
- describe '#log' do
155
- it 'logs an info message through the assigned logger' do
156
- expect(env.logger).to receive(:info).with 'message'
157
- env.log 'message'
158
- end
159
-
160
- context 'when second argument is :warn' do
161
- it 'logs a warning message through the assigned logger' do
162
- expect(env.logger).to receive(:warn).with 'message'
163
- env.log 'message', :warn
164
- end
165
- end
166
- end
167
-
168
- describe '#verbose?' do
169
- it 'returns true when verbose is enabled' do
170
- env.verbose = true
171
- expect(env).to be_verbose
172
- end
173
- end
174
-
175
- describe '#debug?' do
176
- it 'returns true when debug is enabled' do
177
- env.debug = true
178
- expect(env).to be_debug
179
- end
180
- end
181
-
182
- describe '#dry_run?' do
183
- it 'returns true when dry run is enabled' do
184
- env.dry_run = true
185
- expect(env).to be_dry_run
186
- end
187
- end
188
-
189
- describe '#cleanup' do
190
- it 'cleans up the remote' do
191
- expect(env.remote).to receive :cleanup
192
- env.cleanup
193
- end
194
- end
195
- end
196
- end
@@ -1,86 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Producer
4
- module Core
5
- describe ErrorFormatter do
6
- let(:debug) { false }
7
- let(:force_cause) { [] }
8
- let(:options) { { debug: debug, force_cause: force_cause } }
9
- subject(:formatter) { described_class.new(options) }
10
-
11
- describe '#debug?' do
12
- it 'returns false' do
13
- expect(formatter.debug?).to be false
14
- end
15
-
16
- context 'when debug is enabled' do
17
- let(:debug) { true }
18
-
19
- it 'returns true' do
20
- expect(formatter.debug?).to be true
21
- end
22
- end
23
- end
24
-
25
- describe '#format' do
26
- let(:rubylibdir) { RbConfig::CONFIG['rubylibdir'] }
27
- let(:bt) { %W[backtrace /producer /net-ssh #{rubylibdir}] }
28
- let(:exception) { RuntimeError.new('some exception').tap { |o| o.set_backtrace bt } }
29
-
30
- def exception_with_cause
31
- begin fail 'exception cause' rescue fail 'some exception' end
32
- rescue => e
33
- e.tap { |o| o.set_backtrace bt }
34
- end
35
-
36
- it 'formats the message' do
37
- expect(formatter.format exception)
38
- .to match /^RuntimeError: some exception$/
39
- end
40
-
41
- it 'indents the backtrace' do
42
- expect(formatter.format exception).to match /^\s+backtrace$/
43
- end
44
-
45
- it 'excludes producer code from the backtrace' do
46
- expect(formatter.format exception).not_to include 'producer'
47
- end
48
-
49
- it 'excludes net-ssh from the backtrace' do
50
- expect(formatter.format exception).not_to include 'net-ssh'
51
- end
52
-
53
- it 'excludes ruby lib directory from the backtrace' do
54
- expect(formatter.format exception).not_to include rubylibdir
55
- end
56
-
57
- context 'when exception has a cause' do
58
- it 'does not include the cause' do
59
- expect(formatter.format exception_with_cause)
60
- .not_to include 'exception cause'
61
- end
62
- end
63
-
64
- context 'when debug is enabled' do
65
- let(:debug) { true }
66
-
67
- it 'does not filter the backtrace' do
68
- expect(formatter.format exception).to include 'producer'
69
- end
70
-
71
- context 'when exception has a cause' do
72
- it 'includes the exception cause' do
73
- expect(formatter.format exception_with_cause)
74
- .to include 'exception cause'
75
- end
76
-
77
- it 'formats the cause' do
78
- expect(formatter.format exception_with_cause)
79
- .to match /^cause:\nRuntimeError: exception cause/
80
- end
81
- end
82
- end
83
- end
84
- end
85
- end
86
- end
@@ -1,26 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Producer::Core
4
- describe LoggerFormatter do
5
- describe '#call' do
6
- let(:severity) { double 'severity' }
7
- let(:datetime) { double 'datetime' }
8
- let(:progname) { double 'progname' }
9
- let(:message) { 'some message' }
10
-
11
- subject { described_class.new.call(severity, datetime, progname, message) }
12
-
13
- it 'returns the given message with a line separator' do
14
- expect(subject).to eq "#{message}\n"
15
- end
16
-
17
- context 'when severity is WARN' do
18
- let(:severity) { 'WARN' }
19
-
20
- it 'prefix the message with `Warning:\'' do
21
- expect(subject).to match /\AWarning: #{message}/
22
- end
23
- end
24
- end
25
- end
26
- end