Simplify CLI
This commit is contained in:
parent
39427c35c3
commit
d4d1657a4a
@ -24,7 +24,7 @@ module Producer
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_reader :arguments, :stdout, :env, :recipe
|
attr_reader :arguments, :stdout, :env
|
||||||
|
|
||||||
def initialize(args, stdout: $stdout)
|
def initialize(args, stdout: $stdout)
|
||||||
@arguments = args
|
@arguments = args
|
||||||
@ -48,16 +48,15 @@ module Producer
|
|||||||
raise ArgumentError unless arguments.any?
|
raise ArgumentError unless arguments.any?
|
||||||
end
|
end
|
||||||
|
|
||||||
def run(worker: build_worker)
|
def run
|
||||||
load_recipe
|
worker.process load_recipe.tasks
|
||||||
worker.process recipe.tasks
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def load_recipe
|
def load_recipe
|
||||||
@recipe = Recipe.evaluate_from_file(@arguments.first, env)
|
Recipe.evaluate_from_file(@arguments.first, env)
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_worker
|
def worker
|
||||||
Worker.new(env)
|
Worker.new(env)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -132,15 +132,12 @@ module Producer::Core
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe '#run' do
|
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
|
it 'process recipe tasks with given worker' do
|
||||||
worker = double 'worker'
|
worker = double 'worker'
|
||||||
expect(worker).to receive(:process).with [kind_of(Task), kind_of(Task)]
|
allow(cli).to receive(:worker) { worker }
|
||||||
cli.run worker: worker
|
expect(worker).to receive(:process)
|
||||||
|
.with([an_instance_of(Task), an_instance_of(Task)])
|
||||||
|
cli.run
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -157,19 +154,18 @@ module Producer::Core
|
|||||||
cli.load_recipe
|
cli.load_recipe
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'assigns the evaluated recipe' do
|
it 'returns the recipe' do
|
||||||
cli.load_recipe
|
expect(cli.load_recipe).to be_a Recipe
|
||||||
expect(cli.recipe.tasks.count).to be 2
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#build_worker' do
|
describe '#worker' do
|
||||||
it 'returns a worker' do
|
it 'returns a worker' do
|
||||||
expect(cli.build_worker).to be_a Worker
|
expect(cli.worker).to be_a Worker
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'assigns the CLI env' do
|
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
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user