producer-core 0.1.8 → 0.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e267920fce6f6536aa7aeabe841d440bd3ffae7b
4
- data.tar.gz: d9f71061074b02737726ccbbb56f468fdc5e8432
3
+ metadata.gz: 890c789a5de327b39836f468441f8c75b890faeb
4
+ data.tar.gz: c524443e3b5882f32346b144a237bebdc60a477f
5
5
  SHA512:
6
- metadata.gz: c4fd1d85b8191a94838c39f866f3fcb583c9e4a59c7db09b7a37c84d5c0cf096d55ae92d11bba1362cee35f3c7262b1e044075cba0ff82bb6ba2387284aec9d3
7
- data.tar.gz: 5b9e9ea1ec0f4f5ae937c23d53ba115fd9f4427a810b4ea8a674c39dd6289ce59e3389c601244bdc71b0984451ba12e614baafa17e0aea6bebcaa1b90b91887e
6
+ metadata.gz: 3a21fe320fa3ac8c89c92c7def97284413ad31afd620784a255daeeb38fa8db1b005fc1f5db02cd55d801d4ba159985845a87e23addea989ce6a25aa42135629
7
+ data.tar.gz: d4d1389cfe3de827c45d2d6c0982644827d5356352699e2d41d8424772c17abb3d602c04e6b3d8aeacfee599de391c9fc33ddc1c2d245b71f70a63e66bb155f7
@@ -5,19 +5,22 @@ module Producer
5
5
 
6
6
  USAGE = "Usage: #{File.basename $0} recipe_file"
7
7
 
8
+ EX_USAGE = 64
9
+
8
10
  class << self
9
11
  def run!(arguments, output: $stderr)
10
12
  begin
11
13
  cli = new(arguments)
12
14
  rescue ArgumentError
13
15
  output.puts USAGE
14
- exit 64
16
+ exit EX_USAGE
15
17
  end
16
- cli.run!
18
+ cli.run
17
19
  end
18
20
  end
19
21
 
20
22
  attr_reader :arguments, :stdout
23
+ attr_accessor :recipe
21
24
 
22
25
  def initialize(arguments, stdout: $stdout)
23
26
  raise ArgumentError unless arguments.any?
@@ -25,20 +28,13 @@ module Producer
25
28
  @stdout = stdout
26
29
  end
27
30
 
28
- def run!
29
- interpreter.process recipe.tasks
30
- end
31
-
32
- def env
33
- @env ||= Env.new
34
- end
35
-
36
- def recipe
37
- @recipe ||= Recipe.evaluate_from_file(@arguments.first, env)
31
+ def run(worker: Interpreter.new)
32
+ load_recipe
33
+ worker.process recipe.tasks
38
34
  end
39
35
 
40
- def interpreter
41
- @interpreter ||= Interpreter.new
36
+ def load_recipe
37
+ @recipe = Recipe.evaluate_from_file(@arguments.first, Env.new)
42
38
  end
43
39
  end
44
40
  end
@@ -1,5 +1,5 @@
1
1
  module Producer
2
2
  module Core
3
- VERSION = '0.1.8'
3
+ VERSION = '0.1.9'
4
4
  end
5
5
  end
@@ -0,0 +1,5 @@
1
+ task :some_task do
2
+ end
3
+
4
+ task :another_task do
5
+ end
@@ -5,7 +5,7 @@ module Producer::Core
5
5
  include ExitHelpers
6
6
  include FixturesHelpers
7
7
 
8
- let(:recipe_file) { fixture_path_for 'recipes/empty.rb' }
8
+ let(:recipe_file) { fixture_path_for 'recipes/some_recipe.rb' }
9
9
  let(:arguments) { [recipe_file] }
10
10
  let(:stdout) { StringIO.new }
11
11
 
@@ -23,7 +23,7 @@ module Producer::Core
23
23
  it 'runs the CLI' do
24
24
  cli = double 'cli'
25
25
  allow(CLI).to receive(:new) { cli }
26
- expect(cli).to receive :run!
26
+ expect(cli).to receive :run
27
27
  run
28
28
  end
29
29
 
@@ -69,51 +69,37 @@ module Producer::Core
69
69
  end
70
70
  end
71
71
 
72
- describe '#run!' do
73
- it 'processes the tasks with the interpreter' do
74
- allow(cli.recipe).to receive(:tasks) { [:some_task] }
75
- expect(cli.interpreter).to receive(:process).with [:some_task]
76
- cli.run!
72
+ describe '#recipe' do
73
+ it 'returns the assigned recipe' do
74
+ recipe = double 'recipe'
75
+ cli.recipe = recipe
76
+ expect(cli.recipe).to be recipe
77
77
  end
78
78
  end
79
79
 
80
- describe '#env' do
81
- it 'builds an environment with the current recipe' do
82
- expect(Env).to receive :new
83
- cli.env
80
+ describe '#run' do
81
+ it 'loads the recipe' do
82
+ cli.run
83
+ expect(cli.recipe).to be_a Recipe
84
84
  end
85
85
 
86
- it 'returns the env' do
87
- env = double 'env'
88
- allow(Env).to receive(:new) { env }
89
- expect(cli.env).to be env
86
+ it 'process recipe tasks with given worker' do
87
+ worker = double 'worker'
88
+ expect(worker).to receive(:process).with [kind_of(Task), kind_of(Task)]
89
+ cli.run worker: worker
90
90
  end
91
91
  end
92
92
 
93
- describe '#recipe' do
94
- it 'builds a recipe' do
93
+ describe '#load_recipe' do
94
+ it 'evaluates the recipe file with an env' do
95
95
  expect(Recipe)
96
- .to receive(:evaluate_from_file).with(recipe_file, cli.env)
97
- cli.recipe
98
- end
99
-
100
- it 'returns the recipe' do
101
- recipe = double('recipe').as_null_object
102
- allow(Recipe).to receive(:new) { recipe }
103
- expect(cli.recipe).to be recipe
104
- end
105
- end
106
-
107
- describe '#interpreter' do
108
- it 'builds a interpreter' do
109
- expect(Interpreter).to receive :new
110
- cli.interpreter
96
+ .to receive(:evaluate_from_file).with(recipe_file, kind_of(Env))
97
+ cli.load_recipe
111
98
  end
112
99
 
113
- it 'returns the interpreter' do
114
- interpreter = double 'interpreter'
115
- allow(Interpreter).to receive(:new) { interpreter }
116
- expect(cli.interpreter).to be interpreter
100
+ it 'assigns the evaluated recipe' do
101
+ cli.load_recipe
102
+ expect(cli.recipe.tasks.count).to be 2
117
103
  end
118
104
  end
119
105
  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.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thibault Jouan
@@ -154,6 +154,7 @@ files:
154
154
  - lib/producer/core/version.rb
155
155
  - producer-core.gemspec
156
156
  - spec/fixtures/recipes/empty.rb
157
+ - spec/fixtures/recipes/some_recipe.rb
157
158
  - spec/fixtures/recipes/throw.rb
158
159
  - spec/producer/core/action_spec.rb
159
160
  - spec/producer/core/actions/echo_spec.rb
@@ -226,6 +227,7 @@ test_files:
226
227
  - features/tests/has_file.feature
227
228
  - features/tests/negated_test.feature
228
229
  - spec/fixtures/recipes/empty.rb
230
+ - spec/fixtures/recipes/some_recipe.rb
229
231
  - spec/fixtures/recipes/throw.rb
230
232
  - spec/producer/core/action_spec.rb
231
233
  - spec/producer/core/actions/echo_spec.rb