producer-core 0.2.14 → 0.2.15

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 961e79ea57d0b4e4db3b33cc2a0665efbda76aac
4
- data.tar.gz: ef532a17f25bfc0e746ee5af7d14b553beb00419
3
+ metadata.gz: 875191e45bda2ff4554cafda7ebce7eca67887c6
4
+ data.tar.gz: fc971de1aedd2cef0d0187ab41e870091b507978
5
5
  SHA512:
6
- metadata.gz: b7a09c92aabde58b964fc612f1118301deb8d627c9b6b0c447255d740081765b2309b93b04ecd50db556e4e7ee2e3d9f4979b86a36717b7a9c4f0e3e25016072
7
- data.tar.gz: 6d4fec1fe651713a7dcb4ecc52792bc6ca9892504e4ae786a73af6f266ec9dcdefe2bf3072c5e437d5286977432cbcb1074d0a1d52c317a56334a42542b580d2
6
+ metadata.gz: e0d7b779cceb0281e01ea51fdabbf7da0e1a13a1c4d1016dfd321c5aedc63031e82d3195ae546c36a540f823c08682121e9eb4a33602d1f59229b52173f4045c
7
+ data.tar.gz: 7cfe40e211ec6dac6c0bf0d67b8f28fab98b8b600bcad20b62b319ba054ee7a0fb688d276c09d015d22856907510e21c0660a1dc64d7616fde1dd4dcee52dc05
@@ -25,7 +25,7 @@ module Producer
25
25
  end
26
26
  end
27
27
 
28
- attr_reader :arguments, :stdin, :stdout, :stderr, :env
28
+ attr_reader :arguments, :env
29
29
 
30
30
  def initialize(args, stdin: $stdin, stdout: $stdout, stderr: $stderr)
31
31
  @arguments = args
@@ -49,20 +49,16 @@ module Producer
49
49
  m
50
50
  end
51
51
 
52
- fail ArgumentError unless arguments.any?
52
+ fail ArgumentError unless @arguments.any?
53
53
  end
54
54
 
55
- def run
56
- worker.process load_recipe.tasks
57
- env.cleanup
55
+ def run(worker: Worker.new(@env))
56
+ worker.process recipe.tasks
57
+ @env.cleanup
58
58
  end
59
59
 
60
- def load_recipe
61
- Recipe.evaluate_from_file(@arguments.first, env)
62
- end
63
-
64
- def worker
65
- Worker.new(env)
60
+ def recipe
61
+ @recipe ||= Recipe.evaluate_from_file(@arguments.first, env)
66
62
  end
67
63
  end
68
64
  end
@@ -1,5 +1,5 @@
1
1
  module Producer
2
2
  module Core
3
- VERSION = '0.2.14'.freeze
3
+ VERSION = '0.2.15'.freeze
4
4
  end
5
5
  end
@@ -0,0 +1 @@
1
+ fail Producer::Core::RemoteCommandExecutionError, 'false'
@@ -8,108 +8,53 @@ module Producer::Core
8
8
  let(:recipe_file) { fixture_path_for 'recipes/some_recipe.rb' }
9
9
  let(:options) { [] }
10
10
  let(:arguments) { [*options, recipe_file] }
11
- let(:stdin) { StringIO.new}
12
- let(:stdout) { StringIO.new }
13
- let(:stderr) { StringIO.new }
14
11
 
15
- subject(:cli) { described_class.new(
16
- arguments,
17
- stdin: stdin, stdout: stdout, stderr: stderr) }
12
+ subject(:cli) { described_class.new(arguments) }
18
13
 
19
14
  describe '.run!' do
20
- let(:cli) { double('cli').as_null_object }
15
+ let(:stderr) { StringIO.new }
16
+ subject(:run!) { described_class.run! arguments, stderr: stderr }
21
17
 
22
- subject(:run) do
23
- described_class.run! arguments,
24
- stdin: stdin,
25
- stdout: stdout,
26
- stderr: stderr
27
- end
28
-
29
- before { allow(described_class).to receive(:new) { cli } }
30
-
31
- it 'builds a new CLI with given arguments and streams' do
32
- expect(described_class).to receive(:new).with(arguments,
33
- stdin: stdin,
34
- stdout: stdout,
35
- stderr: stderr
36
- )
37
- run
38
- end
39
-
40
- it 'runs the CLI' do
41
- expect(cli).to receive :run
42
- run
43
- end
44
-
45
- it 'parses CLI arguments' do
46
- expect(cli).to receive :parse_arguments!
47
- run
48
- end
49
-
50
- context 'when an argument error is raised' do
51
- before do
52
- allow(cli).to receive(:parse_arguments!)
53
- .and_raise described_class::ArgumentError
54
- end
18
+ context 'when given arguments are invalid' do
19
+ let(:arguments) { [] }
55
20
 
56
21
  it 'exits with a return status of 64' do
57
- expect { run }.to raise_error(SystemExit) do |e|
22
+ expect { run! }.to raise_error(SystemExit) do |e|
58
23
  expect(e.status).to eq 64
59
24
  end
60
25
  end
61
26
 
62
27
  it 'prints the usage on the error stream' do
63
- trap_exit { run }
28
+ trap_exit { run! }
64
29
  expect(stderr.string).to match /\AUsage: .+/
65
30
  end
66
31
  end
67
32
 
68
33
  context 'when a runtime error is raised' do
69
- before do
70
- allow(cli).to receive(:run)
71
- .and_raise RuntimeError, 'some message'
72
- end
34
+ let(:recipe_file) { fixture_path_for 'recipes/raise.rb' }
73
35
 
74
36
  it 'exits with a return status of 70' do
75
- expect { run }.to raise_error(SystemExit) do |e|
37
+ expect { run! }.to raise_error(SystemExit) do |e|
76
38
  expect(e.status).to eq 70
77
39
  end
78
40
  end
79
41
 
80
42
  it 'prints exception name and message and the error stream' do
81
- trap_exit { run }
82
- expect(stderr.string).to match /\ARuntimeError: some message/
43
+ trap_exit { run! }
44
+ expect(stderr.string).to eq "RemoteCommandExecutionError: false\n"
83
45
  end
84
46
  end
85
47
  end
86
48
 
87
- describe '#initialize' do
88
- subject(:cli) { described_class.new(arguments) }
89
-
90
- it 'assigns $stdin as the default standard input' do
91
- expect(cli.stdin).to be $stdin
92
- end
93
-
94
- it 'assigns $stdout as the default standard output' do
95
- expect(cli.stdout).to be $stdout
96
- end
97
- end
98
-
99
- describe '#arguments' do
100
- it 'returns the assigned arguments' do
101
- expect(cli.arguments).to eq arguments
102
- end
103
- end
49
+ describe '#env' do
50
+ let(:stdin) { StringIO.new }
51
+ let(:stdout) { StringIO.new }
52
+ let(:stderr) { StringIO.new }
104
53
 
105
- describe '#stdout' do
106
- it 'returns the assigned standard output' do
107
- expect(cli.stdout).to be stdout
108
- end
109
- end
54
+ subject(:cli) { described_class.new(arguments,
55
+ stdin: stdin, stdout: stdout, stderr: stderr) }
110
56
 
111
- describe '#env' do
112
- it 'returns the assigned env' do
57
+ it 'returns an env' do
113
58
  expect(cli.env).to be_an Env
114
59
  end
115
60
 
@@ -171,12 +116,10 @@ module Producer::Core
171
116
  end
172
117
 
173
118
  describe '#run' do
174
- it 'process recipe tasks with given worker' do
175
- worker = double 'worker'
176
- allow(cli).to receive(:worker) { worker }
177
- expect(worker).to receive(:process)
178
- .with([an_instance_of(Task), an_instance_of(Task)])
179
- cli.run
119
+ it 'processes recipe tasks with a worker' do
120
+ worker = instance_spy Worker
121
+ cli.run worker: worker
122
+ expect(worker).to have_received(:process).with cli.recipe.tasks
180
123
  end
181
124
 
182
125
  it 'cleans up the env' do
@@ -185,25 +128,12 @@ module Producer::Core
185
128
  end
186
129
  end
187
130
 
188
- describe '#load_recipe' do
189
- it 'evaluates the recipe file with the CLI env' do
190
- expect(Recipe)
191
- .to receive(:evaluate_from_file).with(recipe_file, cli.env)
192
- cli.load_recipe
193
- end
194
-
195
- it 'returns the recipe' do
196
- expect(cli.load_recipe).to be_a Recipe
197
- end
198
- end
199
-
200
- describe '#worker' do
201
- it 'returns a worker' do
202
- expect(cli.worker).to be_a Worker
203
- end
204
-
205
- it 'assigns the CLI env' do
206
- expect(cli.worker.env).to eq cli.env
131
+ describe '#recipe' do
132
+ it 'returns the evaluated recipe' do
133
+ expect(cli.recipe.tasks).to match [
134
+ an_object_having_attributes(name: :some_task),
135
+ an_object_having_attributes(name: :another_task)
136
+ ]
207
137
  end
208
138
  end
209
139
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: producer-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.14
4
+ version: 0.2.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thibault Jouan
@@ -195,6 +195,7 @@ files:
195
195
  - lib/producer/core/worker.rb
196
196
  - producer-core.gemspec
197
197
  - spec/fixtures/recipes/empty.rb
198
+ - spec/fixtures/recipes/raise.rb
198
199
  - spec/fixtures/recipes/some_recipe.rb
199
200
  - spec/fixtures/recipes/throw.rb
200
201
  - spec/producer/core/action_spec.rb
@@ -296,6 +297,7 @@ test_files:
296
297
  - features/test_negated_test.feature
297
298
  - features/test_shell_command_status.feature
298
299
  - spec/fixtures/recipes/empty.rb
300
+ - spec/fixtures/recipes/raise.rb
299
301
  - spec/fixtures/recipes/some_recipe.rb
300
302
  - spec/fixtures/recipes/throw.rb
301
303
  - spec/producer/core/action_spec.rb