producer-core/spec/producer/core/condition_spec.rb
Thibault Jouan 639bdc1c73 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.
2013-08-18 00:29:14 +00:00

40 lines
1.0 KiB
Ruby

require 'spec_helper'
module Producer::Core
describe Condition do
let(:expression) { double('expression') }
let(:condition) { Condition.new(expression) }
describe '.evaluate' do
let(:env) { double('env') }
let(:block) { proc { :some_condition_code } }
it 'delegates to DSL.evaluate' do
expect(Condition::DSL)
.to receive(:evaluate).with(env) do |&b|
expect(b.call).to eq :some_condition_code
end
Condition.evaluate(env, &block)
end
it 'returns the evaluated condition' do
condition = double('condition')
allow(Condition::DSL).to receive(:evaluate) { condition }
expect(Condition.evaluate(env, &block)).to be condition
end
end
describe '#initialize' do
it 'assigns the expression' do
expect(condition.instance_eval { @expression }).to be expression
end
end
describe '#!' do
it 'returns the negated expression' do
expect(condition.!).to be !expression
end
end
end
end