From a871bb40091a5d64edb5f0ee1ca589642345f897 Mon Sep 17 00:00:00 2001 From: Thibault Jouan Date: Mon, 20 Jan 2014 22:26:27 +0000 Subject: [PATCH] Implement input handling in Env --- lib/producer/core/env.rb | 5 +++-- spec/producer/core/env_spec.rb | 13 +++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/producer/core/env.rb b/lib/producer/core/env.rb index 515260c..14b0fae 100644 --- a/lib/producer/core/env.rb +++ b/lib/producer/core/env.rb @@ -1,10 +1,11 @@ module Producer module Core class Env - attr_reader :output + attr_reader :input, :output attr_accessor :target - def initialize(output: $stdout) + def initialize(input: $stdin, output: $stdout) + @input = input @output = output @target = nil end diff --git a/spec/producer/core/env_spec.rb b/spec/producer/core/env_spec.rb index 37d2384..ca05e74 100644 --- a/spec/producer/core/env_spec.rb +++ b/spec/producer/core/env_spec.rb @@ -5,6 +5,10 @@ module Producer::Core subject(:env) { Env.new } describe '#initialize' do + it 'assigns $stdin as the default output' do + expect(env.input).to be $stdin + end + it 'assigns $stdout as the default output' do expect(env.output).to be $stdout end @@ -13,6 +17,15 @@ module Producer::Core expect(env.target).not_to be end + context 'when input is given as argument' do + let(:input) { double 'input' } + subject(:env) { described_class.new(input: input) } + + it 'assigns the given input' do + expect(env.input).to eq input + end + end + context 'when output is given as argument' do let(:output) { double 'output' } subject(:env) { described_class.new(output: output) }