Implement nested tasks

This commit is contained in:
Thibault Jouan
2014-09-24 22:26:22 +00:00
parent ede9ea7111
commit 638f8320bc
5 changed files with 48 additions and 6 deletions

View File

@@ -126,6 +126,15 @@ module Producer::Core
end
end
describe '#task' do
before { described_class.define_action(:some_action, SomeAction) }
it 'registers a nested task as an action' do
task.task(:nested_task) { some_action }
expect(task.actions).to match [an_instance_of(Task)]
end
end
describe '#ask' do
let(:question) { 'Which letter?' }
let(:choices) { [[:a, ?A], [:b, ?B]] }

View File

@@ -25,9 +25,9 @@ module Producer::Core
end
describe '#process_task' do
let(:env) { instance_spy Env, dry_run?: false }
let(:action) { double('action', to_s: 'echo').as_null_object }
let(:task) { Task.new(env, :some_task, [action]) }
let(:env) { instance_spy Env, dry_run?: false }
let(:action) { double('action', to_s: 'echo').as_null_object }
let(:task) { Task.new(env, :some_task, [action]) }
it 'logs task info' do
expect(env).to receive(:log).with /\ATask: `some_task'/
@@ -68,11 +68,21 @@ module Producer::Core
worker.process_task task
end
it 'logs the task as beeing skipped' do
it 'logs the task as being skipped' do
expect(env).to receive(:log).with /some_task.+skipped\z/
worker.process_task task
end
end
context 'when a task contains nested tasks' do
let(:inner_task) { Task.new(env, :inner, [action]) }
let(:outer_task) { Task.new(env, :outer, [inner_task]) }
it 'processes nested tasks' do
expect(action).to receive :apply
worker.process [outer_task]
end
end
end
end
end