Use instance_eval in Condition::DSL#evaluate:
Use instance_eval so that the assigned block is evaluated inside the DSL sandbox instance, giving access to all required methods and instance variables.
This commit is contained in:
parent
3a0ce82799
commit
00a11e159f
@ -24,7 +24,7 @@ module Producer
|
||||
end
|
||||
|
||||
def evaluate
|
||||
@block.call
|
||||
instance_eval &@block
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -43,22 +43,6 @@ module Producer::Core
|
||||
it 'defines a new test keyword' do
|
||||
expect(dsl).to respond_to :some_test
|
||||
end
|
||||
|
||||
context 'defined test keyword' do
|
||||
let(:arguments) { [:some, :arguments] }
|
||||
|
||||
it 'builds a new test with the env and given arguments' do
|
||||
expect(some_test_class).to receive(:new).with(env, arguments)
|
||||
dsl.some_test(arguments)
|
||||
end
|
||||
|
||||
it 'registers the new test' do
|
||||
some_test = double('SomeTest instance')
|
||||
allow(some_test_class).to receive(:new) { some_test }
|
||||
dsl.some_test(arguments)
|
||||
expect(dsl.tests).to include(some_test)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#initialize' do
|
||||
@ -86,6 +70,27 @@ module Producer::Core
|
||||
it 'returns the value returned by the assigned block' do
|
||||
expect(dsl.evaluate).to eq block.call
|
||||
end
|
||||
|
||||
context 'when a defined test keyword is called' do
|
||||
let(:some_test_class) { double('SomeTest class') }
|
||||
let(:block) { proc { some_test :some, :args } }
|
||||
|
||||
before do
|
||||
Condition::DSL.define_test(:some_test, some_test_class)
|
||||
end
|
||||
|
||||
it 'builds a new test with the env and given arguments' do
|
||||
expect(some_test_class).to receive(:new).with(env, :some, :args)
|
||||
dsl.evaluate
|
||||
end
|
||||
|
||||
it 'registers the new test' do
|
||||
some_test = double('SomeTest instance')
|
||||
allow(some_test_class).to receive(:new) { some_test }
|
||||
dsl.evaluate
|
||||
expect(dsl.tests).to include(some_test)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user