diff --git a/lib/producer/core/cli.rb b/lib/producer/core/cli.rb index 3d558c8..22f4127 100644 --- a/lib/producer/core/cli.rb +++ b/lib/producer/core/cli.rb @@ -24,7 +24,7 @@ module Producer end end - attr_reader :arguments, :stdout, :env, :recipe + attr_reader :arguments, :stdout, :env def initialize(args, stdout: $stdout) @arguments = args @@ -48,16 +48,15 @@ module Producer raise ArgumentError unless arguments.any? end - def run(worker: build_worker) - load_recipe - worker.process recipe.tasks + def run + worker.process load_recipe.tasks end def load_recipe - @recipe = Recipe.evaluate_from_file(@arguments.first, env) + Recipe.evaluate_from_file(@arguments.first, env) end - def build_worker + def worker Worker.new(env) end end diff --git a/spec/producer/core/cli_spec.rb b/spec/producer/core/cli_spec.rb index c99ba30..08e8721 100644 --- a/spec/producer/core/cli_spec.rb +++ b/spec/producer/core/cli_spec.rb @@ -132,15 +132,12 @@ module Producer::Core end describe '#run' do - it 'loads the recipe' do - cli.run - expect(cli.recipe).to be_a Recipe - end - it 'process recipe tasks with given worker' do worker = double 'worker' - expect(worker).to receive(:process).with [kind_of(Task), kind_of(Task)] - cli.run worker: worker + allow(cli).to receive(:worker) { worker } + expect(worker).to receive(:process) + .with([an_instance_of(Task), an_instance_of(Task)]) + cli.run end end @@ -157,19 +154,18 @@ module Producer::Core cli.load_recipe end - it 'assigns the evaluated recipe' do - cli.load_recipe - expect(cli.recipe.tasks.count).to be 2 + it 'returns the recipe' do + expect(cli.load_recipe).to be_a Recipe end end - describe '#build_worker' do + describe '#worker' do it 'returns a worker' do - expect(cli.build_worker).to be_a Worker + expect(cli.worker).to be_a Worker end it 'assigns the CLI env' do - expect(cli.build_worker.env).to eq cli.env + expect(cli.worker.env).to eq cli.env end end end