Implement basic condition DSL framework for tests:
Instead of interrupting task evaluation when condition is not met, allow the whole task to be evaluated (including condition and evaluation) so that the interpreter will get all tasks actions (whether condition is met or not) and be able to query the condition. * Modify Interpreter#process_task: test if task condition is met before applying the actions; * Implement condition handling in Task and Task::DSL; * Implement Condition and Condition::DSL (useless as they are, but needed to implement later test keywords as part of the condition DSL.
This commit is contained in:
@@ -4,7 +4,8 @@ module Producer::Core
|
||||
describe Task do
|
||||
let(:name) { :some_task }
|
||||
let(:action) { double('action') }
|
||||
subject(:task) { Task.new(name, [action]) }
|
||||
let(:condition) { double('condition') }
|
||||
subject(:task) { Task.new(name, [action], condition) }
|
||||
|
||||
describe '.evaluate' do
|
||||
let(:env) { double('env') }
|
||||
@@ -34,12 +35,20 @@ module Producer::Core
|
||||
expect(task.instance_eval { @actions }).to eq [action]
|
||||
end
|
||||
|
||||
it 'assigns the condition' do
|
||||
expect(task.instance_eval { @condition }).to eq condition
|
||||
end
|
||||
|
||||
context 'when only the name is given as argument' do
|
||||
subject(:task) { Task.new(name) }
|
||||
|
||||
it 'assigns no action' do
|
||||
expect(task.actions).to be_empty
|
||||
end
|
||||
|
||||
it 'assigns a truthy condition' do
|
||||
expect(task.condition).to be_true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -54,5 +63,29 @@ module Producer::Core
|
||||
expect(task.actions).to eq [action]
|
||||
end
|
||||
end
|
||||
|
||||
describe '#condition' do
|
||||
it 'returns the assigned condition' do
|
||||
expect(task.condition).to be condition
|
||||
end
|
||||
end
|
||||
|
||||
describe '#condition_met?' do
|
||||
context 'when condition is truthy' do
|
||||
let(:condition) { Condition.new(true) }
|
||||
|
||||
it 'returns true' do
|
||||
expect(task.condition_met?).to be true
|
||||
end
|
||||
end
|
||||
|
||||
context 'when condition is falsy' do
|
||||
let(:condition) { Condition.new(false) }
|
||||
|
||||
it 'returns false' do
|
||||
expect(task.condition_met?).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user