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).
This commit is contained in:
Thibault Jouan 2014-04-24 18:38:58 +00:00
parent fc5d35ceb5
commit 25b1394178

View File

@ -4,38 +4,39 @@ module Producer::Core
module Tests module Tests
describe HasEnv do describe HasEnv do
let(:env) { Env.new } 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) } subject(:has_env) { HasEnv.new(env, variable_name) }
it_behaves_like 'test' it_behaves_like 'test'
describe '#verify' do
let(:environment) { double 'environment' }
before do before do
allow(env.remote).to receive(:environment) { environment } allow(env.remote).to receive(:environment) { remote_env }
end end
it 'stringifies the queried variable name' do describe '#verify' do
expect(environment).to receive(:key?).with(kind_of(String)) context 'remote environment var is defined' do
has_env.verify it 'returns true' do
end
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 expect(has_env.verify).to be true
end end
it 'returns false when remote environment var is not defined' do context 'when var name is given as a lowercase symbol' do
allow(environment).to receive(:key?) { false } let(:variable_name) { :some_var }
it 'returns true' do
expect(has_env.verify).to be true
end
end
end
context 'remote environment var is not defined' do
let(:variable_name) { 'SOME_NON_EXISTENT_VAR' }
it 'returns false' do
expect(has_env.verify).to be false expect(has_env.verify).to be false
end end
end end
end end
end end
end
end end