Remove Task::DSL.evaluate method

This commit is contained in:
Thibault Jouan 2013-12-20 11:43:18 +00:00
parent 366c682152
commit 43a781dc78
4 changed files with 28 additions and 50 deletions

View File

@ -3,7 +3,9 @@ module Producer
class Task
class << self
def evaluate(name, env, &block)
DSL.evaluate(name, env, &block)
dsl = DSL.new(&block)
dsl.evaluate(env)
Task.new(name, dsl.actions, dsl.condition)
end
end

View File

@ -3,12 +3,6 @@ module Producer
class Task
class DSL
class << self
def evaluate(name, env, &block)
dsl = new(&block)
dsl.evaluate(env)
Task.new(name, dsl.actions, dsl.condition)
end
def define_action(keyword, klass)
define_method(keyword) do |*args|
@actions << klass.new(@env, *args)

View File

@ -12,42 +12,6 @@ module Producer::Core
end
end
describe '.evaluate' do
let(:name) { :some_task }
it 'builds a new DSL sandbox with given code' do
dsl = double('dsl').as_null_object
expect(Task::DSL).to receive(:new).with(no_args) do |&b|
expect(b).to be block
dsl
end
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, actions and condition' do
dsl = double(
'dsl', actions: [:some_action], condition: :some_condition
).as_null_object
allow(Task::DSL).to receive(:new) { dsl }
expect(Task)
.to receive(:new).with(:some_task, [:some_action], :some_condition)
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)

View File

@ -11,17 +11,35 @@ module Producer::Core
let(:env) { double 'env' }
let(:block) { proc { :some_task_code } }
it 'delegates to DSL.evaluate' do
expect(Task::DSL)
.to receive(:evaluate).with(name, env) do |&b|
expect(b).to be block
end
it 'builds a new DSL sandbox with given code' do
dsl = double('dsl').as_null_object
expect(Task::DSL).to receive(:new).with(no_args) do |&b|
expect(b).to be block
dsl
end
Task.evaluate(name, env, &block)
end
it 'returns the evaluated task' do
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.evaluate(name, env, &block)
end
it 'builds the task with its name, actions and condition' do
dsl = double(
'dsl', actions: [:some_action], condition: :some_condition
).as_null_object
allow(Task::DSL).to receive(:new) { dsl }
expect(Task)
.to receive(:new).with(:some_task, [:some_action], :some_condition)
Task.evaluate(name, env, &block)
end
it 'returns the task' do
task = double 'task'
allow(Task::DSL).to receive(:evaluate) { task }
allow(Task).to receive(:new) { task }
expect(Task.evaluate(name, env, &block)).to be task
end
end