Refactor task DSL usages:

Remove most of task evaluation code from Task class, rely on
Task::DSL.evaluate to get an evaluated task.

* Task: remove #evaluate, change constructor prototype to accept actions
  instead of a block, implement .evaluate(name, env &block);
* Implement Task::DSL.evaluate method;
* Recipe::DSL: remove tasks evaluation from#evaluate, modify #task to
  use Task.evaluate to return the new task to be rigstered.
This commit is contained in:
Thibault Jouan
2013-08-15 21:03:06 +00:00
parent 000c21e094
commit d4d5222261
6 changed files with 83 additions and 52 deletions

View File

@@ -12,6 +12,36 @@ module Producer::Core
end
end
describe '.evaluate' do
let(:name) { :some_task }
it 'builds a new DSL sandbox with given code' do
expect(Task::DSL).to receive(:new).once.with(&block).and_call_original
Task::DSL.evaluate(name, env, &block)
end
it 'evaluates the DSL sandbox code with given environment' do
dsl = double('dsl').as_null_object
allow(Task::DSL).to receive(:new) { dsl }
expect(dsl).to receive(:evaluate).with(env)
Task::DSL.evaluate(name, env, &block)
end
it 'builds a task with its name and registered actions' do
dsl = double('dsl').as_null_object
allow(Task::DSL).to receive(:new) { dsl }
allow(dsl).to receive(:actions) { [:some_action]}
expect(Task).to receive(:new).with(:some_task, [:some_action])
Task::DSL.evaluate(name, env, &block)
end
it 'returns the task' do
task = double('task')
allow(Task).to receive(:new) { task }
expect(Task::DSL.evaluate(name, env, &block)).to be task
end
end
describe '.define_action' do
it 'defines a new action keyword' do
Task::DSL.define_action(:some_action, Object)