require 'spec_helper'

describe Vcloud::Fog::Login do
  let!(:mock_env) { ENV.clone }

  before(:each) do
    stub_const('ENV', mock_env)
  end

  describe "#token" do
    context "unable to load credentials" do
      it "should raise an exception succinctly listing the missing credentials" do
        mock_env.clear
        ::Fog.credential = 'null'
        ::Fog.credentials_path = '/dev/null'

        # This test is known to fail with a TypeError due to a bug in Ruby 1.9.3 that
        # has since been fixed. See https://github.com/gds-operations/vcloud-core/pull/100
        expect { ::Fog.credentials['doesnotexist'] }.to raise_error(
          Fog::Errors::LoadError,
          /^Missing Credentials\n/
        )
        expect { subject.token(@real_password) }.to raise_error(
          ArgumentError,
          /^Missing required arguments: vcloud_director_.*$/
        )
      end
    end
  end
end

require 'spec_helper'

describe Vcloud::Fog::Login do
  before(:each) do
    stub_const('ENV', {})
  end

  describe "#token" do
    context "unable to load credentials" do
      it "should raise an exception succinctly listing the missing credentials" do
        ::Fog.credential = 'null'
        ::Fog.credentials_path = '/dev/null'

        # This test is known to fail with a TypeError due to a bug in Ruby 1.9.3 that
        # has since been fixed. See https://github.com/gds-operations/vcloud-core/pull/100
        expect { ::Fog.credentials['doesnotexist'] }.to raise_error(
          Fog::Errors::LoadError,
          /^Missing Credentials\n/
        )
        expect { subject.token(@real_password) }.to raise_error(
          ArgumentError,
          /^Missing required arguments: vcloud_director_.*$/
        )
      end
    end
  end
end

Replace ENV.clone mock with empty hash
Replace ENV.clone mock with empty hash

ENV.clone only performs a shallow-copy of the ENV object. Which means that
`mock_env.clear` wipes the real ENV object and affects other tests that run
after this.

We didn't notice it because this is currently the last test picked up by
`rake integration`, but when we attempted to move it in #108 it made all of
the other tests fail. This can also be tested by placing the following at
the end of this spec file:

    describe 'after' do
      it { expect(ENV.to_hash).to_not eq({}) }
    end

Replace it with an empty hash. While this isn't truly the same as the ENV
object because it doesn't implement all of the same methods it should
suffice for the things that Fog needs.

I don't think the `login_manual.rb` test is affected because it uses
`ENV.to_hash` instead. However, since this test it only run manually, I
don't think it matters that much right now.
