From 8375890c1b9b139b923009b58b6f3b8a104b71b6 Mon Sep 17 00:00:00 2001 From: Thibault Jouan Date: Tue, 1 Jul 2014 20:02:35 +0000 Subject: [PATCH] Simplify Remote::Environment --- lib/producer/core/remote.rb | 2 +- lib/producer/core/remote/environment.rb | 13 ------ spec/producer/core/remote/environment_spec.rb | 40 ++----------------- 3 files changed, 5 insertions(+), 50 deletions(-) diff --git a/lib/producer/core/remote.rb b/lib/producer/core/remote.rb index 351b359..5c7b16d 100644 --- a/lib/producer/core/remote.rb +++ b/lib/producer/core/remote.rb @@ -42,7 +42,7 @@ module Producer end def environment - Environment.new_from_string(execute 'env') + Environment.string_to_hash(execute 'env') end def cleanup diff --git a/lib/producer/core/remote/environment.rb b/lib/producer/core/remote/environment.rb index 7238858..8c4b3f8 100644 --- a/lib/producer/core/remote/environment.rb +++ b/lib/producer/core/remote/environment.rb @@ -6,19 +6,6 @@ module Producer def string_to_hash(str) Hash[str.each_line.map { |l| l.chomp.split '=', 2 }] end - - def new_from_string(str) - new string_to_hash str - end - end - - extend Forwardable - def_delegators :@variables, :[], :key? - - attr_reader :variables - - def initialize(variables) - @variables = variables end end end diff --git a/spec/producer/core/remote/environment_spec.rb b/spec/producer/core/remote/environment_spec.rb index 602a5cc..9f4d799 100644 --- a/spec/producer/core/remote/environment_spec.rb +++ b/spec/producer/core/remote/environment_spec.rb @@ -3,47 +3,15 @@ require 'spec_helper' module Producer::Core class Remote describe Environment do - let(:variables) { { 'FOO' => 'bar', 'BAZ' => 'qux' } } let(:string) { "FOO=bar\nBAZ=qux" } let(:argument) { variables } - subject(:environment) { Environment.new(argument) } describe '.string_to_hash' do it 'converts key=value pairs separated by new lines to a hash' do - expect(described_class.string_to_hash(string)).to eq variables - end - end - - describe '.new_from_string' do - it 'returns a new instance with converted keys and values' do - environment = described_class.new_from_string string - expect(environment.variables).to eq variables - end - end - - describe '#initialize' do - it 'assigns the key/value pairs' do - expect(environment.variables).to eq variables - end - end - - describe '#key?' do - context 'when key is defined' do - it 'returns true' do - expect(environment.key? 'FOO').to be true - end - end - - context 'when key is not defined' do - it 'returns false' do - expect(environment.key? 'INEXISTENT_KEY').to be false - end - end - end - - describe '#[]' do - it 'returns the value indexed by given key' do - expect(environment['FOO']).to eq 'bar' + expect(described_class.string_to_hash(string)).to eq ({ + 'FOO' => 'bar', + 'BAZ' => 'qux' + }) end end end