Sha256: 5a0ebc41606045c6bd729084e0efd40df0b182113562d0ce3d261f92c238b587

Contents?: true

Size: 1.2 KB

Versions: 5

Compression:

Stored size: 1.2 KB

Contents

require 'spec_helper'

describe Aptible::CLI::Agent do
  before { subject.stub(:ask) }

  describe '#version' do
    it 'should print the version' do
      version = Aptible::CLI::VERSION
      expect(STDOUT).to receive(:puts).with "aptible-cli v#{version}"
      subject.version
    end
  end

  describe '#login' do
    let(:token) { double('Aptible::Auth::Token') }

    before { OAuth2::Error.send :define_method, :initialize, -> {} }
    before { token.stub(:access_token) { 'access_token' } }

    it 'should save a token to ~/.aptible/tokens' do
      Aptible::Auth::Token.stub(:create) { token }
      expect(subject).to receive(:save_token).with('access_token')
      subject.login
    end

    it 'should raise an error if authentication fails' do
      Aptible::Auth::Token.stub(:create).and_raise OAuth2::Error
      expect do
        subject.login
      end.to raise_error 'Could not authenticate with given credentials'
    end

    it 'should use command line arguments if passed' do
      options = { email: 'test@example.com', password: 'password' }
      subject.stub(:options) { options }
      expect(Aptible::Auth::Token).to receive(:create).with(options) { token }
      subject.login
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
aptible-cli-0.3.7 spec/aptible/cli/agent_spec.rb
aptible-cli-0.3.6 spec/aptible/cli/agent_spec.rb
aptible-cli-0.3.5 spec/aptible/cli/agent_spec.rb
aptible-cli-0.3.4 spec/aptible/cli/agent_spec.rb
aptible-cli-0.3.3 spec/aptible/cli/agent_spec.rb