Sha256: f453531f270529c327e39d6ae7bd097f75dd72161a4b55cba984c713b79debdf

Contents?: true

Size: 1.46 KB

Versions: 14

Compression:

Stored size: 1.46 KB

Contents

require 'spec_helper'
require 'fileutils'
require 'paratrooper/local_api_key_extractor'

describe Paratrooper::LocalApiKeyExtractor do
  let(:netrc_klass) { double(:netrc_klass, default_path: fixture_file_path) }
  let(:fixture_file_path) { fixture_path('netrc') }

  before do
    File.chmod(0600, fixture_file_path)
  end

  describe 'file association' do
    context 'when file path is provided' do
      let(:extractor) { described_class.new(file_path: fixture_file_path) }

      it 'uses provided file path' do
        expect(extractor.file_path).to eq(fixture_file_path)
      end
    end

    context 'when file path is not provided' do
      let(:extractor) { described_class.new(netrc_klass: netrc_klass) }

      it 'uses default path' do
        expect(extractor.file_path).to eq(netrc_klass.default_path)
      end
    end
  end

  describe '#read_credentials' do
      let(:extractor) { described_class.new(netrc_klass: netrc_klass) }

    context 'when environment variable is set' do
      before do
        ENV.stub(:[]).with('HEROKU_API_KEY').and_return('ENV_API_KEY')
      end

      it 'returns credentials' do
        expect(extractor.read_credentials).to eq('ENV_API_KEY')
      end
    end

    context 'when environment variable is not set' do
      before do
        ENV.stub(:[]).with('HEROKU_API_KEY').and_return(nil)
      end
      it 'returns credentials from local file' do
        expect(extractor.read_credentials).to eq('LOCAL_API_KEY')
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
paratrooper-2.0.0.beta1 spec/paratrooper/local_api_key_extractor_spec.rb
paratrooper-1.4.2 spec/paratrooper/local_api_key_extractor_spec.rb
paratrooper-1.4.1 spec/paratrooper/local_api_key_extractor_spec.rb
paratrooper-1.4.0 spec/paratrooper/local_api_key_extractor_spec.rb
paratrooper-1.3.2 spec/paratrooper/local_api_key_extractor_spec.rb
paratrooper-1.3.1 spec/paratrooper/local_api_key_extractor_spec.rb
paratrooper-1.2.2 spec/paratrooper/local_api_key_extractor_spec.rb
paratrooper-1.2.1 spec/paratrooper/local_api_key_extractor_spec.rb
paratrooper-1.2.0 spec/paratrooper/local_api_key_extractor_spec.rb
paratrooper-1.1.3 spec/paratrooper/local_api_key_extractor_spec.rb
paratrooper-1.1.2 spec/paratrooper/local_api_key_extractor_spec.rb
paratrooper-1.1.1 spec/paratrooper/local_api_key_extractor_spec.rb
paratrooper-1.1.0 spec/paratrooper/local_api_key_extractor_spec.rb
paratrooper-1.0.0 spec/paratrooper/local_api_key_extractor_spec.rb