Add Env#output with $stdout as default
This commit is contained in:
parent
e6c14f1903
commit
0cccbc8dde
@ -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
|
||||
|
@ -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 }
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user