Remove Recipe::DSL.evaluate method
This commit is contained in:
parent
d83b11d07b
commit
366c682152
@ -3,7 +3,8 @@ module Producer
|
||||
class Recipe
|
||||
class << self
|
||||
def evaluate_from_file(filepath, env)
|
||||
DSL.evaluate(File.read(filepath), env)
|
||||
dsl = DSL.new(File.read(filepath)).evaluate(env)
|
||||
Recipe.new(dsl.tasks)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -2,13 +2,6 @@ module Producer
|
||||
module Core
|
||||
class Recipe
|
||||
class DSL
|
||||
class << self
|
||||
def evaluate(code, env)
|
||||
dsl = new(code).evaluate(env)
|
||||
Recipe.new(dsl.tasks)
|
||||
end
|
||||
end
|
||||
|
||||
attr_reader :tasks
|
||||
|
||||
def initialize(code = nil, &block)
|
||||
|
@ -8,35 +8,6 @@ module Producer::Core
|
||||
let(:env) { double('env').as_null_object }
|
||||
subject(:dsl) { Recipe::DSL.new(&code) }
|
||||
|
||||
describe '.evaluate' do
|
||||
let(:code) { 'nil' }
|
||||
|
||||
it 'builds a new DSL sandbox with given code as string' do
|
||||
expect(Recipe::DSL).to receive(:new).with(code).and_call_original
|
||||
Recipe::DSL.evaluate(code, env)
|
||||
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::DSL.evaluate(code, 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::DSL.evaluate(code, env)
|
||||
end
|
||||
|
||||
it 'returns the recipe' do
|
||||
recipe = double('recipe').as_null_object
|
||||
allow(Recipe).to receive(:new) { recipe }
|
||||
expect(Recipe::DSL.evaluate(code, env)).to be recipe
|
||||
end
|
||||
end
|
||||
|
||||
describe '#initialize' do
|
||||
it 'assigns no task' do
|
||||
expect(dsl.instance_eval { @tasks }).to be_empty
|
||||
|
@ -9,18 +9,33 @@ module Producer::Core
|
||||
describe '.evaluate_from_file' do
|
||||
let(:env) { double 'env' }
|
||||
let(:filepath) { fixture_path_for 'recipes/empty.rb' }
|
||||
let(:code) { File.read(filepath) }
|
||||
|
||||
it 'delegates to DSL.evaluate with the recipe file content' do
|
||||
expect(Recipe::DSL)
|
||||
.to receive(:evaluate).with(File.read(filepath), env)
|
||||
it 'builds a new DSL sandbox with code read from given file path' do
|
||||
expect(Recipe::DSL).to receive(:new).with(code).and_call_original
|
||||
Recipe.evaluate_from_file(filepath, env)
|
||||
end
|
||||
|
||||
it 'returns the evaluated recipe' do
|
||||
recipe = double 'recipe'
|
||||
allow(Recipe::DSL).to receive(:evaluate) { recipe }
|
||||
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
|
||||
|
||||
describe '#initialize' do
|
||||
|
Loading…
x
Reference in New Issue
Block a user