Improve exceptions usage in specs:
* Throw symbols instead of raising exceptions to test code evaluation, this will reduce "bad" usages of exceptions, symbols seems a little better for now; * Add a specific exception to be used in specs for testing behaviour when an exception is raised from a recipe.
This commit is contained in:
@@ -6,11 +6,11 @@ module Producer::Core
|
||||
subject(:dsl) { Task::DSL.new &block }
|
||||
|
||||
describe '#evaluate' do
|
||||
let(:block) { proc { raise 'error from task' } }
|
||||
let(:block) { proc { throw :task_code } }
|
||||
|
||||
it 'evaluates its code' do
|
||||
expect { dsl.evaluate(env) }
|
||||
.to raise_error(RuntimeError, 'error from task')
|
||||
.to throw_symbol :task_code
|
||||
end
|
||||
|
||||
context 'when given block is invalid' do
|
||||
@@ -26,23 +26,23 @@ module Producer::Core
|
||||
context 'when met (block evals to true)' do
|
||||
let(:block) { proc {
|
||||
condition { true }
|
||||
raise 'error after condition'
|
||||
throw :after_condition
|
||||
} }
|
||||
|
||||
it 'evaluates all the block' do
|
||||
expect { dsl.evaluate(env) }
|
||||
.to raise_error(RuntimeError, 'error after condition')
|
||||
.to throw_symbol :after_condition
|
||||
end
|
||||
end
|
||||
|
||||
context 'when not met (block evals to false)' do
|
||||
let(:block) { proc {
|
||||
condition { false }
|
||||
raise
|
||||
throw :after_condition
|
||||
} }
|
||||
|
||||
it 'stops block evaluation' do
|
||||
expect { dsl.evaluate(env) }.not_to raise_error
|
||||
expect { dsl.evaluate(env) }.not_to throw_symbol :after_condition
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user