diff --git a/lib/producer/core/testing/mock_remote.rb b/lib/producer/core/testing/mock_remote.rb index 331281e..9a472ea 100644 --- a/lib/producer/core/testing/mock_remote.rb +++ b/lib/producer/core/testing/mock_remote.rb @@ -5,6 +5,20 @@ module Producer def session raise 'no session for mock remote!' end + + def execute(command) + tokens = command.split + program = tokens.shift + + case program + when 'echo' + tokens.join ' ' + when 'true' + '' + when 'false' + raise RemoteCommandExecutionError + end + end end end end diff --git a/spec/producer/core/testing/mock_remote_spec.rb b/spec/producer/core/testing/mock_remote_spec.rb index adfd7c1..aef8238 100644 --- a/spec/producer/core/testing/mock_remote_spec.rb +++ b/spec/producer/core/testing/mock_remote_spec.rb @@ -1,3 +1,4 @@ +require 'spec_helper' require 'producer/core/testing' module Producer::Core @@ -14,6 +15,32 @@ module Producer::Core expect { remote.session }.to raise_error end end + + describe '#execute' do + context 'dummy echo command' do + let(:command) { 'echo some arguments' } + + it 'returns command arguments' do + expect(remote.execute(command)).to eq 'some arguments' + end + end + + context 'dummy true command' do + let(:command) { 'true' } + + it 'returns an empty string' do + expect(remote.execute(command)).to eq '' + end + end + + context 'dummy false command' do + let(:command) { 'false' } + + it 'raises a RemoteCommandExecutionError' do + expect { remote.execute(command) }.to raise_error(RemoteCommandExecutionError) + end + end + end end end end