diff --git a/lib/producer/core/env.rb b/lib/producer/core/env.rb index 76edb59..d95cff0 100644 --- a/lib/producer/core/env.rb +++ b/lib/producer/core/env.rb @@ -2,12 +2,18 @@ module Producer module Core class Env attr_reader :current_recipe + attr_writer :output attr_accessor :target def initialize(recipe = nil) @current_recipe = recipe + @output = $stdout @target = nil end + + def output(str) + @output.puts str + end end end end diff --git a/spec/producer/core/env_spec.rb b/spec/producer/core/env_spec.rb index 5575852..4d8850c 100644 --- a/spec/producer/core/env_spec.rb +++ b/spec/producer/core/env_spec.rb @@ -13,6 +13,10 @@ module Producer::Core it 'has 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 @@ -25,6 +29,16 @@ module Producer::Core end end + describe '#output' do + let(:standard_output) { StringIO.new } + + it 'writes the given string to the assigned IO with a record separator' do + env.output = standard_output + expect(standard_output).to receive(:puts).with('some content') + env.output 'some content' + end + end + describe '#target' do let(:target) { Object.new }