Implement Action#remote (delegates to env.remote)
This commit is contained in:
parent
e567c61e4e
commit
29c26ab961
@ -4,7 +4,7 @@ module Producer
|
||||
require 'forwardable'
|
||||
|
||||
extend Forwardable
|
||||
def_delegator :@env, :output
|
||||
def_delegators :@env, :output, :remote
|
||||
|
||||
attr_accessor :env, :arguments
|
||||
|
||||
|
@ -3,7 +3,7 @@ module Producer
|
||||
module Actions
|
||||
class FileWriter < Action
|
||||
def apply
|
||||
env.remote.fs.file_write path, content
|
||||
remote.fs.file_write path, content
|
||||
end
|
||||
|
||||
def path
|
||||
|
@ -3,7 +3,7 @@ module Producer
|
||||
module Actions
|
||||
class ShellCommand < Action
|
||||
def apply
|
||||
output.puts env.remote.execute(arguments.first)
|
||||
output.puts remote.execute(arguments.first)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -2,7 +2,8 @@ require 'spec_helper'
|
||||
|
||||
module Producer::Core
|
||||
describe Action do
|
||||
let(:env) { double 'env' }
|
||||
let(:output) { StringIO.new }
|
||||
let(:env) { Env.new(output: output) }
|
||||
let(:arguments) { [:some, :arguments] }
|
||||
subject(:action) { Action.new(env, *arguments) }
|
||||
|
||||
@ -20,8 +21,14 @@ module Producer::Core
|
||||
|
||||
describe '#output' do
|
||||
it 'delegates to env output' do
|
||||
expect(action.env).to receive(:output).with(:content)
|
||||
action.output :content
|
||||
action.output.puts 'some content'
|
||||
expect(output.string).to eq "some content\n"
|
||||
end
|
||||
end
|
||||
|
||||
describe '#remote' do
|
||||
it 'returns env remote' do
|
||||
expect(action.remote).to be action.env.remote
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -8,8 +8,8 @@ module Producer::Core
|
||||
subject(:writer) { Actions::FileWriter.new(env, path, content) }
|
||||
|
||||
describe '#apply' do
|
||||
it 'delegates the call to env.remote.fs.file_write method' do
|
||||
expect(env.remote.fs).to receive(:file_write).with(path, content)
|
||||
it 'writes the content to remote file' do
|
||||
expect(writer.remote.fs).to receive(:file_write).with(path, content)
|
||||
writer.apply
|
||||
end
|
||||
end
|
||||
|
@ -8,17 +8,15 @@ module Producer::Core
|
||||
subject(:sh) { Actions::ShellCommand.new(env, command) }
|
||||
|
||||
describe '#apply' do
|
||||
before { env.output = StringIO.new }
|
||||
|
||||
it 'delegates the call to env.remote.execute method' do
|
||||
expect(env.remote).to receive(:execute).with(command)
|
||||
it 'executes the remote command' do
|
||||
expect(sh.remote).to receive(:execute).with(command)
|
||||
sh.apply
|
||||
end
|
||||
|
||||
it 'writes the returned output to env.output with a record separator' do
|
||||
allow(env.remote).to receive(:execute) { command_args }
|
||||
it 'writes the returned output with a record separator' do
|
||||
allow(sh.remote).to receive(:execute) { command_args }
|
||||
sh.apply
|
||||
expect(env.output.string).to eq "#{command_args}\n"
|
||||
expect(sh.output.string).to eq "#{command_args}\n"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user