Add Env class
This commit is contained in:
@@ -13,16 +13,26 @@ module Producer::Core
|
||||
end
|
||||
end
|
||||
|
||||
# FIXME: spec/method need refactoring
|
||||
describe '#run!' do
|
||||
it 'builds a recipe' do
|
||||
expect(Recipe).to receive(:from_file).with(arguments[1]).and_call_original
|
||||
cli.run!
|
||||
end
|
||||
|
||||
it 'evaluates the recipe' do
|
||||
it 'builds an environment with the current recipe' do
|
||||
recipe = double('recipe').as_null_object
|
||||
allow(Recipe).to receive(:from_file).and_return(recipe)
|
||||
expect(Env).to receive(:new).with(recipe).and_call_original
|
||||
cli.run!
|
||||
end
|
||||
|
||||
it 'evaluates the recipe with the environment' do
|
||||
recipe = double('recipe')
|
||||
allow(Recipe).to receive(:from_file).and_return(recipe)
|
||||
expect(recipe).to receive(:evaluate)
|
||||
env = double('env')
|
||||
allow(Env).to receive(:new).and_return(env)
|
||||
expect(recipe).to receive(:evaluate).with(env)
|
||||
cli.run!
|
||||
end
|
||||
|
||||
|
14
spec/producer/core/env_spec.rb
Normal file
14
spec/producer/core/env_spec.rb
Normal file
@@ -0,0 +1,14 @@
|
||||
require 'spec_helper'
|
||||
|
||||
module Producer::Core
|
||||
describe Env do
|
||||
let(:recipe) { Recipe.new(Proc.new { nil }) }
|
||||
subject(:env) { Env.new(recipe) }
|
||||
|
||||
describe '#current_recipe' do
|
||||
it 'returns the assigned current recipe' do
|
||||
expect(env.current_recipe).to eq recipe
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@@ -5,6 +5,7 @@ module Producer::Core
|
||||
include FixturesHelpers
|
||||
|
||||
let(:code) { 'nil' }
|
||||
let(:env) { double('env') }
|
||||
subject(:recipe) { Recipe.new(code) }
|
||||
|
||||
describe '.from_file' do
|
||||
@@ -35,7 +36,7 @@ module Producer::Core
|
||||
describe '#evaluate' do
|
||||
it 'builds a recipe DSL sandbox' do
|
||||
expect(Recipe::DSL).to receive(:new).with(code).and_call_original
|
||||
recipe.evaluate
|
||||
recipe.evaluate(env)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -65,23 +66,23 @@ module Producer::Core
|
||||
describe '#evaluate' do
|
||||
it 'evaluates its code' do
|
||||
dsl = Recipe::DSL.new { raise 'error from recipe' }
|
||||
expect { dsl.evaluate }.to raise_error(RuntimeError, 'error from recipe')
|
||||
expect { dsl.evaluate(env) }.to raise_error(RuntimeError, 'error from recipe')
|
||||
end
|
||||
|
||||
it 'returns itself' do
|
||||
expect(dsl.evaluate).to eq dsl
|
||||
expect(dsl.evaluate(env)).to eq dsl
|
||||
end
|
||||
end
|
||||
|
||||
context 'DSL specific methods' do
|
||||
subject(:dsl) { Recipe::DSL.new(&code).evaluate }
|
||||
subject(:dsl) { Recipe::DSL.new(&code).evaluate(env) }
|
||||
|
||||
describe '#source' do
|
||||
let(:code) { "source '#{fixture_path_for 'recipes/error'}'" }
|
||||
subject(:dsl) { Recipe::DSL.new code }
|
||||
|
||||
it 'sources the recipe given as argument' do
|
||||
expect { dsl.evaluate }.to raise_error(RuntimeError, 'error from recipe')
|
||||
expect { dsl.evaluate(env) }.to raise_error(RuntimeError, 'error from recipe')
|
||||
end
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user