Sha256: 647a57d9cd8e0b5a95acb50e8363d8c3cca494230edc2e0872d7139beb638824

Contents?: true

Size: 1.29 KB

Versions: 13

Compression:

Stored size: 1.29 KB

Contents

require 'spec_helper'

describe EY::API do
  it "gets the api token from ~/.eyrc if possible" do
    write_eyrc({"api_token" => "asdf"})
    EY::API.new.should == EY::API.new("asdf")
  end

  context "fetching the token from EY cloud" do
    before(:each) do
      FakeWeb.register_uri(:post, "https://cloud.engineyard.com/api/v2/authenticate", :body => %|{"api_token": "asdf"}|, :content_type => 'application/json')
      @token = EY::API.fetch_token("a@b.com", "foo")
    end

    it "returns an EY::API" do
      @token.should == "asdf"
    end

    it "puts the api token into .eyrc" do
      read_eyrc["api_token"].should == "asdf"
    end
  end

  it "raises InvalidCredentials when the credentials are invalid" do
    FakeWeb.register_uri(:post, "https://cloud.engineyard.com/api/v2/authenticate", :status => 401, :content_type => 'application/json')

    lambda {
      EY::API.fetch_token("a@b.com", "foo")
    }.should raise_error(EY::Error)
  end

  it "raises RequestFailed with a friendly error when cloud is under maintenance" do
    FakeWeb.register_uri(:post, "https://cloud.engineyard.com/api/v2/authenticate", :status => 502, :content_type => 'text/html')

    lambda {
      EY::API.fetch_token("a@b.com", "foo")
    }.should raise_error(EY::API::RequestFailed, /API is temporarily unavailable/)
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
engineyard-1.4.29 spec/engineyard/api_spec.rb
engineyard-1.4.28 spec/engineyard/api_spec.rb
engineyard-1.4.27 spec/engineyard/api_spec.rb
engineyard-1.4.24 spec/engineyard/api_spec.rb
engineyard-1.4.23 spec/engineyard/api_spec.rb
engineyard-1.4.22 spec/engineyard/api_spec.rb
engineyard-1.4.21 spec/engineyard/api_spec.rb
engineyard-1.4.20 spec/engineyard/api_spec.rb
engineyard-1.4.19 spec/engineyard/api_spec.rb
engineyard-1.4.18 spec/engineyard/api_spec.rb
engineyard-1.4.17 spec/engineyard/api_spec.rb
engineyard-1.4.16 spec/engineyard/api_spec.rb
engineyard-1.4.15 spec/engineyard/api_spec.rb