Stub ATLAS_TOKEN in tests

Without this stub, the tests will fail if ATLAS_TOKEN is set locally 
when running the tests.
This commit is contained in:
Seth Vargo 2014-12-14 23:28:14 -05:00
parent a4d05c8071
commit f06703cdb1
2 changed files with 13 additions and 0 deletions

View File

@ -17,6 +17,7 @@ describe VagrantPlugins::LoginCommand::AddAuthentication do
before do
allow(Vagrant).to receive(:server_url).and_return(server_url)
stub_env("ATLAS_TOKEN" => nil)
end
describe "#call" do

View File

@ -83,6 +83,18 @@ shared_context "unit" do
return Pathname.new(d)
end
# Stub the given environment in ENV, without actually touching ENV. Keys and
# values are converted to strings because that's how the real ENV works.
def stub_env(hash)
allow(ENV).to receive(:[]).and_call_original
hash.each do |key, value|
allow(ENV).to receive(:[])
.with(key.to_s)
.and_return(value.to_s)
end
end
# This helper provides temporary environmental variable changes.
def with_temp_env(environment)
# Build up the new environment, preserving the old values so we