Remove Condition::DSL.evaluate method
This commit is contained in:
parent
9422705ad4
commit
d83b11d07b
@ -3,7 +3,9 @@ module Producer
|
|||||||
class Condition
|
class Condition
|
||||||
class << self
|
class << self
|
||||||
def evaluate(env, &block)
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -3,12 +3,6 @@ module Producer
|
|||||||
class Condition
|
class Condition
|
||||||
class DSL
|
class DSL
|
||||||
class << self
|
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)
|
def define_test(keyword, klass)
|
||||||
define_method(keyword) do |*args|
|
define_method(keyword) do |*args|
|
||||||
@tests << klass.new(@env, *args)
|
@tests << klass.new(@env, *args)
|
||||||
|
@ -12,33 +12,6 @@ module Producer::Core
|
|||||||
end
|
end
|
||||||
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
|
describe '.define_test' do
|
||||||
let(:some_test_class) { double 'SomeTest class' }
|
let(:some_test_class) { double 'SomeTest class' }
|
||||||
|
|
||||||
|
@ -11,17 +11,28 @@ module Producer::Core
|
|||||||
let(:env) { double 'env' }
|
let(:env) { double 'env' }
|
||||||
let(:block) { proc { :some_condition_code } }
|
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)
|
expect(Condition::DSL)
|
||||||
.to receive(:evaluate).with(env) do |&b|
|
.to receive(:new).with(env, &block).and_call_original
|
||||||
expect(b).to be block
|
|
||||||
end
|
|
||||||
Condition.evaluate(env, &block)
|
Condition.evaluate(env, &block)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns the evaluated condition' do
|
it 'evaluates the DSL sandbox code' do
|
||||||
condition = double 'condition'
|
dsl = double('dsl').as_null_object
|
||||||
allow(Condition::DSL).to receive(:evaluate) { condition }
|
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
|
expect(Condition.evaluate(env, &block)).to be condition
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user