Replace env.output interface with an IO like object

This commit is contained in:
Thibault Jouan
2013-12-23 00:50:25 +00:00
parent e8b0900721
commit d670d5dbdd
6 changed files with 23 additions and 21 deletions

View File

@@ -2,14 +2,14 @@ require 'spec_helper'
module Producer::Core
describe Actions::Echo do
let(:env) { double 'env' }
let(:env) { Env.new(output: StringIO.new) }
let(:text) { 'hello' }
subject(:echo) { Actions::Echo.new(env, text) }
describe '#apply' do
it 'outputs the string given as argument through env.output' do
expect(env).to receive(:output).with(text)
it 'writes the given string to env.output with a record separator' do
echo.apply
expect(env.output.string).to eq "hello\n"
end
end
end

View File

@@ -2,7 +2,7 @@ require 'spec_helper'
module Producer::Core
describe Actions::ShellCommand do
let(:env) { Env.new }
let(:env) { Env.new(output: StringIO.new) }
let(:command_args) { 'hello from remote host' }
let(:command) { "echo #{command_args}" }
subject(:sh) { Actions::ShellCommand.new(env, command) }
@@ -15,10 +15,10 @@ module Producer::Core
sh.apply
end
it 'forwards the returned output to env.output' do
it 'writes the returned output to env.output with a record separator' do
allow(env.remote).to receive(:execute) { command_args }
expect(env).to receive(:output).with(command_args)
sh.apply
expect(env.output.string).to eq "#{command_args}\n"
end
end
end