Refactor Recipe specs:

* Use more classic specs for .evaluate_from_file;
* Fix coding standards.
This commit is contained in:
Thibault Jouan 2014-01-08 02:28:24 +00:00
parent b1010e44c5
commit edca69ffad

View File

@ -7,35 +7,13 @@ module Producer::Core
subject(:recipe) { Recipe.new } subject(:recipe) { Recipe.new }
describe '.evaluate_from_file' do describe '.evaluate_from_file' do
let(:env) { double 'env' } let(:env) { double 'env' }
let(:filepath) { fixture_path_for 'recipes/empty.rb' } let(:filepath) { fixture_path_for 'recipes/some_recipe.rb' }
let(:code) { File.read(filepath) } subject(:recipe) { Recipe.evaluate_from_file(filepath, env) }
it 'builds a new DSL sandbox with code read from given file path' do it 'returns an evaluated recipe' do
expect(Recipe::DSL).to receive(:new).with(code).and_call_original expect(recipe.tasks.map(&:name)).to eq [:some_task, :another_task]
Recipe.evaluate_from_file(filepath, env)
end end
it 'evaluates the DSL sandbox code with given environment' do
dsl = double('dsl').as_null_object
allow(Recipe::DSL).to receive(:new) { dsl }
expect(dsl).to receive(:evaluate).with(env)
Recipe.evaluate_from_file(filepath, env)
end
it 'builds a recipe with evaluated tasks' do
dsl = Recipe::DSL.new { task(:some_task) { } }
allow(Recipe::DSL).to receive(:new) { dsl }
expect(Recipe).to receive(:new).with(dsl.tasks)
Recipe.evaluate_from_file(filepath, env)
end
it 'returns the recipe' do
recipe = double('recipe').as_null_object
allow(Recipe).to receive(:new) { recipe }
expect(Recipe.evaluate_from_file(filepath, env)).to be recipe
end
end end
describe '#initialize' do describe '#initialize' do
@ -46,8 +24,8 @@ module Producer::Core
end end
context 'when tasks are given as argument' do context 'when tasks are given as argument' do
let(:tasks) { [Task.new(:some_task)] } let(:tasks) { [double('task')] }
let(:recipe) { Recipe.new(tasks) } subject(:recipe) { Recipe.new(tasks) }
it 'assigns the tasks' do it 'assigns the tasks' do
expect(recipe.tasks).to eq tasks expect(recipe.tasks).to eq tasks