From b0ea7d876e48a62b84883556a0a9e91cef074d23 Mon Sep 17 00:00:00 2001 From: Thibault Jouan Date: Sun, 18 Aug 2013 20:04:01 +0000 Subject: [PATCH] Implement Remote#environment: Build and return a Remote::Environment instance, with the output of `env` command execution. --- lib/producer/core/remote.rb | 4 ++++ spec/producer/core/remote_spec.rb | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/lib/producer/core/remote.rb b/lib/producer/core/remote.rb index 998b679..e5152b2 100644 --- a/lib/producer/core/remote.rb +++ b/lib/producer/core/remote.rb @@ -31,6 +31,10 @@ module Producer session.loop output end + + def environment + Environment.new(execute 'env') + end end end end diff --git a/spec/producer/core/remote_spec.rb b/spec/producer/core/remote_spec.rb index c1435eb..2475f84 100644 --- a/spec/producer/core/remote_spec.rb +++ b/spec/producer/core/remote_spec.rb @@ -60,5 +60,28 @@ module Producer::Core .to raise_error(RemoteCommandExecutionError) end end + + describe '#environment', :ssh do + let(:command) { 'env' } + let(:output) { "FOO=bar\nBAZ=qux" } + + before do + story_with_new_channel do |ch| + ch.sends_exec command + ch.gets_data output + end + end + + it 'builds a remote environment with the result of `env` command' do + expect(Remote::Environment).to receive(:new).with(output) + remote.environment + end + + it 'returns the environment' do + environment = double('environment') + allow(Remote::Environment).to receive(:new) { environment } + expect(remote.environment).to be environment + end + end end end