From 8e455fc4d5581003c6ca795cbdb7cde6efa58b9f Mon Sep 17 00:00:00 2001 From: Thibault Jouan Date: Sun, 4 Aug 2013 01:17:33 +0000 Subject: [PATCH] Improve Env constructor --- lib/producer/core/env.rb | 2 +- spec/producer/core/env_spec.rb | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/producer/core/env.rb b/lib/producer/core/env.rb index 25adf51..76edb59 100644 --- a/lib/producer/core/env.rb +++ b/lib/producer/core/env.rb @@ -4,7 +4,7 @@ module Producer attr_reader :current_recipe attr_accessor :target - def initialize(recipe) + def initialize(recipe = nil) @current_recipe = recipe @target = nil end diff --git a/spec/producer/core/env_spec.rb b/spec/producer/core/env_spec.rb index 64354e9..5575852 100644 --- a/spec/producer/core/env_spec.rb +++ b/spec/producer/core/env_spec.rb @@ -2,18 +2,26 @@ require 'spec_helper' module Producer::Core describe Env do - let(:recipe) { Recipe.new(proc { nil }) } - subject(:env) { Env.new(recipe) } + subject(:env) { Env.new } describe '#initialize' do it 'has no target' do expect(env.target).not_to be end - end - describe '#current_recipe' do - it 'returns the assigned current recipe' do - expect(env.current_recipe).to eq recipe + context 'without argument' do + it 'has no recipe' do + expect(env.current_recipe).not_to be + 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 eq recipe + end end end