Remove Env#current_recipe attribute
This commit is contained in:
parent
a5d9ca26f4
commit
53db841b2d
@ -3,8 +3,7 @@ Feature: `env' recipe keyword
|
|||||||
Scenario: exposes the internal env object
|
Scenario: exposes the internal env object
|
||||||
Given a recipe with:
|
Given a recipe with:
|
||||||
"""
|
"""
|
||||||
puts env.current_recipe.filepath
|
env
|
||||||
"""
|
"""
|
||||||
When I execute the recipe
|
When I execute the recipe
|
||||||
Then the exit status must be 0
|
Then the exit status must be 0
|
||||||
And the output must contain exactly "recipe.rb\n"
|
|
||||||
|
@ -21,7 +21,7 @@ module Producer
|
|||||||
end
|
end
|
||||||
|
|
||||||
def env
|
def env
|
||||||
@env ||= Env.new(recipe)
|
@env ||= Env.new
|
||||||
end
|
end
|
||||||
|
|
||||||
def recipe
|
def recipe
|
||||||
|
@ -1,14 +1,12 @@
|
|||||||
module Producer
|
module Producer
|
||||||
module Core
|
module Core
|
||||||
class Env
|
class Env
|
||||||
attr_reader :current_recipe
|
|
||||||
attr_writer :output
|
attr_writer :output
|
||||||
attr_accessor :target
|
attr_accessor :target
|
||||||
|
|
||||||
def initialize(recipe = nil)
|
def initialize
|
||||||
@current_recipe = recipe
|
@output = $stdout
|
||||||
@output = $stdout
|
@target = nil
|
||||||
@target = nil
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def output(str)
|
def output(str)
|
||||||
|
@ -13,7 +13,7 @@ module Producer
|
|||||||
def evaluate(env)
|
def evaluate(env)
|
||||||
@env = env
|
@env = env
|
||||||
if @code
|
if @code
|
||||||
instance_eval @code, env.current_recipe.filepath
|
instance_eval @code
|
||||||
else
|
else
|
||||||
instance_eval &@block
|
instance_eval &@block
|
||||||
end
|
end
|
||||||
|
@ -66,7 +66,7 @@ module Producer::Core
|
|||||||
|
|
||||||
describe '#env' do
|
describe '#env' do
|
||||||
it 'builds an environment with the current recipe' do
|
it 'builds an environment with the current recipe' do
|
||||||
expect(Env).to receive(:new).with(cli.recipe)
|
expect(Env).to receive(:new)
|
||||||
cli.env
|
cli.env
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -5,28 +5,13 @@ module Producer::Core
|
|||||||
subject(:env) { Env.new }
|
subject(:env) { Env.new }
|
||||||
|
|
||||||
describe '#initialize' do
|
describe '#initialize' do
|
||||||
|
it 'assigns $stdout as the default output' do
|
||||||
|
expect(env.instance_eval { @output }).to eq $stdout
|
||||||
|
end
|
||||||
|
|
||||||
it 'assigns nil as a default target' do
|
it 'assigns nil as a default target' do
|
||||||
expect(env.target).not_to be
|
expect(env.target).not_to be
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'without argument' do
|
|
||||||
it 'assigns no recipe' do
|
|
||||||
expect(env.current_recipe).not_to be
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'assigns $stdout as the default output' do
|
|
||||||
expect(env.instance_eval { @output }).to eq $stdout
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'when a recipe is given as argument' do
|
|
||||||
let(:recipe) { Recipe.new(proc { nil }) }
|
|
||||||
subject(:env) { Env.new(recipe) }
|
|
||||||
|
|
||||||
it 'assigns the current recipe' do
|
|
||||||
expect(env.current_recipe).to be recipe
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#output' do
|
describe '#output' do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user