Remove Condition::DSL.evaluate method

This commit is contained in:
Thibault Jouan 2013-12-20 11:01:48 +00:00
parent 9422705ad4
commit d83b11d07b
4 changed files with 21 additions and 41 deletions

View File

@ -3,7 +3,9 @@ module Producer
class Condition
class << self
def evaluate(env, &block)
DSL.evaluate(env, &block)
dsl = DSL.new(env, &block)
return_value = dsl.evaluate
Condition.new(dsl.tests, return_value)
end
end

View File

@ -3,12 +3,6 @@ module Producer
class Condition
class DSL
class << self
def evaluate(env, &block)
dsl = new(env, &block)
return_value = dsl.evaluate
Condition.new(dsl.tests, return_value)
end
def define_test(keyword, klass)
define_method(keyword) do |*args|
@tests << klass.new(@env, *args)

View File

@ -12,33 +12,6 @@ module Producer::Core
end
end
describe '.evaluate' do
it 'builds a new DSL sandbox with given env and code' do
expect(Condition::DSL)
.to receive(:new).with(env, &block).and_call_original
Condition::DSL.evaluate(env, &block)
end
it 'evaluates the DSL sandbox code' do
dsl = double('dsl').as_null_object
allow(Condition::DSL).to receive(:new) { dsl }
expect(dsl).to receive :evaluate
Condition::DSL.evaluate(env, &block)
end
it 'builds a condition with its test and block return value' do
expect(Condition)
.to receive(:new).with(dsl.tests, :some_condition_code)
Condition::DSL.evaluate(env, &block)
end
it 'returns the condition' do
condition = double 'task'
allow(Condition).to receive(:new) { condition }
expect(Condition::DSL.evaluate(env, &block)).to be condition
end
end
describe '.define_test' do
let(:some_test_class) { double 'SomeTest class' }

View File

@ -11,17 +11,28 @@ module Producer::Core
let(:env) { double 'env' }
let(:block) { proc { :some_condition_code } }
it 'delegates to DSL.evaluate' do
it 'builds a new DSL sandbox with given env and code' do
expect(Condition::DSL)
.to receive(:evaluate).with(env) do |&b|
expect(b).to be block
end
.to receive(:new).with(env, &block).and_call_original
Condition.evaluate(env, &block)
end
it 'returns the evaluated condition' do
condition = double 'condition'
allow(Condition::DSL).to receive(:evaluate) { condition }
it 'evaluates the DSL sandbox code' do
dsl = double('dsl').as_null_object
allow(Condition::DSL).to receive(:new) { dsl }
expect(dsl).to receive :evaluate
Condition.evaluate(env, &block)
end
it 'builds a condition with its test and block return value' do
expect(Condition)
.to receive(:new).with([], :some_condition_code)
Condition.evaluate(env, &block)
end
it 'returns the condition' do
condition = double 'task'
allow(Condition).to receive(:new) { condition }
expect(Condition.evaluate(env, &block)).to be condition
end
end