diff --git a/lib/producer/core/action.rb b/lib/producer/core/action.rb index 6f67297..4678f18 100644 --- a/lib/producer/core/action.rb +++ b/lib/producer/core/action.rb @@ -4,7 +4,7 @@ module Producer require 'forwardable' extend Forwardable - def_delegator :@env, :output + def_delegators :@env, :output, :remote attr_accessor :env, :arguments diff --git a/lib/producer/core/actions/file_writer.rb b/lib/producer/core/actions/file_writer.rb index dd2f192..b142204 100644 --- a/lib/producer/core/actions/file_writer.rb +++ b/lib/producer/core/actions/file_writer.rb @@ -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 diff --git a/lib/producer/core/actions/shell_command.rb b/lib/producer/core/actions/shell_command.rb index 6431337..9a12656 100644 --- a/lib/producer/core/actions/shell_command.rb +++ b/lib/producer/core/actions/shell_command.rb @@ -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 diff --git a/spec/producer/core/action_spec.rb b/spec/producer/core/action_spec.rb index 65aab5e..8da6338 100644 --- a/spec/producer/core/action_spec.rb +++ b/spec/producer/core/action_spec.rb @@ -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 diff --git a/spec/producer/core/actions/file_writer_spec.rb b/spec/producer/core/actions/file_writer_spec.rb index 60fa8e8..20cbaee 100644 --- a/spec/producer/core/actions/file_writer_spec.rb +++ b/spec/producer/core/actions/file_writer_spec.rb @@ -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 diff --git a/spec/producer/core/actions/shell_command_spec.rb b/spec/producer/core/actions/shell_command_spec.rb index 4edb571..61d0ffe 100644 --- a/spec/producer/core/actions/shell_command_spec.rb +++ b/spec/producer/core/actions/shell_command_spec.rb @@ -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