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