Attach our env to the worker from the CLI
This commit is contained in:
parent
024ab7eba0
commit
7cffa34442
@ -19,21 +19,26 @@ module Producer
|
||||
end
|
||||
end
|
||||
|
||||
attr_reader :arguments, :stdout, :recipe
|
||||
attr_reader :arguments, :stdout, :env, :recipe
|
||||
|
||||
def initialize(arguments, stdout: $stdout)
|
||||
raise ArgumentError unless arguments.any?
|
||||
@arguments = arguments
|
||||
def initialize(args, stdout: $stdout)
|
||||
@arguments = args
|
||||
@stdout = stdout
|
||||
@env = Env.new(output: stdout)
|
||||
raise ArgumentError unless arguments.any?
|
||||
end
|
||||
|
||||
def run(worker: Worker.new)
|
||||
def run(worker: build_worker)
|
||||
load_recipe
|
||||
worker.process recipe.tasks
|
||||
end
|
||||
|
||||
def load_recipe
|
||||
@recipe = Recipe.evaluate_from_file(@arguments.first, Env.new)
|
||||
@recipe = Recipe.evaluate_from_file(@arguments.first, env)
|
||||
end
|
||||
|
||||
def build_worker
|
||||
Worker.new(env)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,6 +1,12 @@
|
||||
module Producer
|
||||
module Core
|
||||
class Worker
|
||||
attr_accessor :env
|
||||
|
||||
def initialize(env)
|
||||
@env = env
|
||||
end
|
||||
|
||||
def process(tasks)
|
||||
tasks.each { |t| process_task t }
|
||||
end
|
||||
|
@ -44,10 +44,16 @@ module Producer::Core
|
||||
end
|
||||
|
||||
describe '#initialize' do
|
||||
subject(:cli) { CLI.new(arguments) }
|
||||
it 'assigns the env with CLI output' do
|
||||
expect(cli.env.output).to be stdout
|
||||
end
|
||||
|
||||
it 'assigns $stdout as the default standard output' do
|
||||
expect(cli.stdout).to be $stdout
|
||||
context 'without options' do
|
||||
subject(:cli) { CLI.new(arguments) }
|
||||
|
||||
it 'assigns $stdout as the default standard output' do
|
||||
expect(cli.stdout).to be $stdout
|
||||
end
|
||||
end
|
||||
|
||||
context 'without arguments' do
|
||||
@ -84,10 +90,16 @@ module Producer::Core
|
||||
end
|
||||
end
|
||||
|
||||
describe '#env' do
|
||||
it 'returns an env' do
|
||||
expect(cli.env).to be_an Env
|
||||
end
|
||||
end
|
||||
|
||||
describe '#load_recipe' do
|
||||
it 'evaluates the recipe file with an env' do
|
||||
it 'evaluates the recipe file with the CLI env' do
|
||||
expect(Recipe)
|
||||
.to receive(:evaluate_from_file).with(recipe_file, kind_of(Env))
|
||||
.to receive(:evaluate_from_file).with(recipe_file, cli.env)
|
||||
cli.load_recipe
|
||||
end
|
||||
|
||||
@ -96,5 +108,15 @@ module Producer::Core
|
||||
expect(cli.recipe.tasks.count).to be 2
|
||||
end
|
||||
end
|
||||
|
||||
describe '#build_worker' do
|
||||
it 'returns a worker' do
|
||||
expect(cli.build_worker).to be_a Worker
|
||||
end
|
||||
|
||||
it 'assigns the CLI env' do
|
||||
expect(cli.build_worker.env).to eq cli.env
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -2,7 +2,8 @@ require 'spec_helper'
|
||||
|
||||
module Producer::Core
|
||||
describe Worker do
|
||||
subject(:worker) { described_class.new }
|
||||
let(:env) { Env.new }
|
||||
subject(:worker) { described_class.new(env) }
|
||||
|
||||
describe '#process' do
|
||||
it 'processes each task' do
|
||||
@ -31,5 +32,11 @@ module Producer::Core
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#env' do
|
||||
it 'returns the assigned env' do
|
||||
expect(worker.env).to be env
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user