From fc5d35ceb5c8a73d0456e8a43d9626d58ff5390c Mon Sep 17 00:00:00 2001 From: Thibault Jouan Date: Thu, 24 Apr 2014 15:52:25 +0000 Subject: [PATCH 1/2] Fix subject name in HasExecutable specs --- spec/producer/core/tests/has_executable_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/producer/core/tests/has_executable_spec.rb b/spec/producer/core/tests/has_executable_spec.rb index 4ea161f..0a40ad1 100644 --- a/spec/producer/core/tests/has_executable_spec.rb +++ b/spec/producer/core/tests/has_executable_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' module Producer::Core module Tests describe HasExecutable, :env do - subject(:has_env) { HasExecutable.new(env, executable) } + subject(:test) { HasExecutable.new(env, executable) } it_behaves_like 'test' @@ -12,7 +12,7 @@ module Producer::Core let(:executable) { 'true' } it 'returns true' do - expect(has_env.verify).to be true + expect(test.verify).to be true end end @@ -20,7 +20,7 @@ module Producer::Core let(:executable) { 'some_non_existent_executable' } it 'returns false' do - expect(has_env.verify).to be false + expect(test.verify).to be false end end end From 25b1394178d84a5f653d8856938d672750f222db Mon Sep 17 00:00:00 2001 From: Thibault Jouan Date: Thu, 24 Apr 2014 18:38:58 +0000 Subject: [PATCH 2/2] Improve HasEnv specs: * Use a more classic style, and rely on a simple Hash instead of stubbing a double; * Improve examples to show the intent more clearly (like the use of a symbol when querying). --- spec/producer/core/tests/has_env_spec.rb | 43 ++++++++++++------------ 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/spec/producer/core/tests/has_env_spec.rb b/spec/producer/core/tests/has_env_spec.rb index 3085048..e82456f 100644 --- a/spec/producer/core/tests/has_env_spec.rb +++ b/spec/producer/core/tests/has_env_spec.rb @@ -4,36 +4,37 @@ module Producer::Core module Tests describe HasEnv do let(:env) { Env.new } - let(:variable_name) { :some_variable_name } + let(:variable_name) { 'SOME_VAR' } + let(:remote_env) { { 'SOME_VAR' => 'SOME_VALUE' } } subject(:has_env) { HasEnv.new(env, variable_name) } it_behaves_like 'test' + before do + allow(env.remote).to receive(:environment) { remote_env } + end + describe '#verify' do - let(:environment) { double 'environment' } + context 'remote environment var is defined' do + it 'returns true' do + expect(has_env.verify).to be true + end - before do - allow(env.remote).to receive(:environment) { environment } + context 'when var name is given as a lowercase symbol' do + let(:variable_name) { :some_var } + + it 'returns true' do + expect(has_env.verify).to be true + end + end end - it 'stringifies the queried variable name' do - expect(environment).to receive(:key?).with(kind_of(String)) - has_env.verify - end + context 'remote environment var is not defined' do + let(:variable_name) { 'SOME_NON_EXISTENT_VAR' } - it 'upcases the queried variable name' do - expect(environment).to receive(:key?).with('SOME_VARIABLE_NAME') - has_env.verify - end - - it 'returns true when remote environment var is defined' do - allow(environment).to receive(:key?) { true } - expect(has_env.verify).to be true - end - - it 'returns false when remote environment var is not defined' do - allow(environment).to receive(:key?) { false } - expect(has_env.verify).to be false + it 'returns false' do + expect(has_env.verify).to be false + end end end end