Sha256: 7f8ab93844fc9d6698da0c7a96cc584ac5ae5612d89261d091b714f28cc6b216

Contents?: true

Size: 1.23 KB

Versions: 27

Compression:

Stored size: 1.23 KB

Contents

require 'spec_helper'

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

  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

27 entries across 27 versions & 1 rubygems

Version Path
aptible-cli-0.6.7 spec/aptible/cli/agent_spec.rb
aptible-cli-0.6.6 spec/aptible/cli/agent_spec.rb
aptible-cli-0.6.4 spec/aptible/cli/agent_spec.rb
aptible-cli-0.6.3 spec/aptible/cli/agent_spec.rb
aptible-cli-0.6.2 spec/aptible/cli/agent_spec.rb
aptible-cli-0.6.1 spec/aptible/cli/agent_spec.rb
aptible-cli-0.6.0 spec/aptible/cli/agent_spec.rb
aptible-cli-0.5.15 spec/aptible/cli/agent_spec.rb
aptible-cli-0.5.14 spec/aptible/cli/agent_spec.rb
aptible-cli-0.5.13 spec/aptible/cli/agent_spec.rb
aptible-cli-0.5.12 spec/aptible/cli/agent_spec.rb
aptible-cli-0.5.11 spec/aptible/cli/agent_spec.rb
aptible-cli-0.5.10 spec/aptible/cli/agent_spec.rb
aptible-cli-0.5.9 spec/aptible/cli/agent_spec.rb
aptible-cli-0.5.8 spec/aptible/cli/agent_spec.rb
aptible-cli-0.5.7 spec/aptible/cli/agent_spec.rb
aptible-cli-0.5.6 spec/aptible/cli/agent_spec.rb
aptible-cli-0.5.5 spec/aptible/cli/agent_spec.rb
aptible-cli-0.5.4 spec/aptible/cli/agent_spec.rb
aptible-cli-0.5.2 spec/aptible/cli/agent_spec.rb