Implement tasks condition feature
This commit is contained in:
@@ -3,7 +3,7 @@ require 'spec_helper'
|
||||
module Producer::Core
|
||||
describe Task do
|
||||
let(:name) { :some_task }
|
||||
let(:block) { }
|
||||
let(:block) { Proc.new { } }
|
||||
subject(:task) { Task.new(name, &block) }
|
||||
|
||||
describe '#name' do
|
||||
@@ -12,11 +12,46 @@ module Producer::Core
|
||||
end
|
||||
end
|
||||
|
||||
describe 'evaluate' do
|
||||
let(:block) { Proc.new { raise 'error from task' } }
|
||||
describe '#evaluate' do
|
||||
it 'builds a task DSL sandbox' do
|
||||
expect(Task::DSL).to receive(:new).with(&block)
|
||||
task.evaluate
|
||||
end
|
||||
end
|
||||
|
||||
it 'evaluates its block' do
|
||||
expect { task.evaluate }.to raise_error(RuntimeError, 'error from task')
|
||||
describe Task::DSL do
|
||||
let(:dsl) { Task::DSL.new &block }
|
||||
|
||||
describe '#initialize' do
|
||||
let(:block) { Proc.new { raise 'error from task' } }
|
||||
|
||||
it 'evaluates its block' do
|
||||
expect { dsl }.to raise_error(RuntimeError, 'error from task')
|
||||
end
|
||||
end
|
||||
|
||||
describe '#condition' do
|
||||
context 'condition is met (block evals to true)' do
|
||||
let(:block) { Proc.new {
|
||||
condition { true }
|
||||
raise 'error after condition'
|
||||
} }
|
||||
|
||||
it 'evaluates all the block' do
|
||||
expect { dsl }.to raise_error(RuntimeError, 'error after condition')
|
||||
end
|
||||
end
|
||||
|
||||
context 'condition is not met (block evals to false)' do
|
||||
let(:block) { Proc.new {
|
||||
condition { false }
|
||||
raise
|
||||
} }
|
||||
|
||||
it 'evaluates all the block' do
|
||||
expect { dsl }.not_to raise_error
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user