Add Env#output with $stdout as default
This commit is contained in:
parent
e6c14f1903
commit
0cccbc8dde
@ -2,12 +2,18 @@ module Producer
|
|||||||
module Core
|
module Core
|
||||||
class Env
|
class Env
|
||||||
attr_reader :current_recipe
|
attr_reader :current_recipe
|
||||||
|
attr_writer :output
|
||||||
attr_accessor :target
|
attr_accessor :target
|
||||||
|
|
||||||
def initialize(recipe = nil)
|
def initialize(recipe = nil)
|
||||||
@current_recipe = recipe
|
@current_recipe = recipe
|
||||||
|
@output = $stdout
|
||||||
@target = nil
|
@target = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def output(str)
|
||||||
|
@output.puts str
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -13,6 +13,10 @@ module Producer::Core
|
|||||||
it 'has no recipe' do
|
it 'has no recipe' do
|
||||||
expect(env.current_recipe).not_to be
|
expect(env.current_recipe).not_to be
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'assigns $stdout as the default output' do
|
||||||
|
expect(env.instance_eval { @output} ).to eq $stdout
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when a recipe is given as argument' do
|
context 'when a recipe is given as argument' do
|
||||||
@ -25,6 +29,16 @@ module Producer::Core
|
|||||||
end
|
end
|
||||||
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
|
describe '#target' do
|
||||||
let(:target) { Object.new }
|
let(:target) { Object.new }
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user