Sha256: 5a9f450dba99089bfb5b2d255ab46a210e383d8a6eb31ed7997fa96bef66faaa

Contents?: true

Size: 1.17 KB

Versions: 23

Compression:

Stored size: 1.17 KB

Contents

require 'spec_helper'
require 'engineyard/cli'

describe EY::CLI::API do
  before(:all) do
    EY.ui = EY::CLI::UI.new
  end

  after(:all) do
    EY.ui = EY::UI.new
  end

  it "gets the api token from ~/.eyrc if possible" do
    File.open(File.expand_path("~/.eyrc"), "w") do |fp|
      YAML.dump({"api_token" => "asdf"}, fp)
    end

    EY::CLI::API.new.should == EY::CLI::API.new("asdf")
  end

  context "without saved api token" do
    before(:each) do
      FakeWeb.register_uri(:post, "https://cloud.engineyard.com/api/v2/authenticate", :body => %|{"api_token": "asdf"}|, :content_type => 'application/json')

      EY::CLI::UI::Prompter.enable_mock!
      EY::CLI::UI::Prompter.backend.next_answer = "my@email.example.com"
      EY::CLI::UI::Prompter.backend.next_answer = "secret"

      @token = EY::CLI::API.new
    end

    it "asks you for your credentials" do
      EY::CLI::UI::Prompter.backend.questions.should == ["Email: ","Password: "]
    end

    it "gets the api token" do
      @token.should == EY::CLI::API.new("asdf")
    end

    it "saves the api token to ~/.eyrc" do
      YAML.load_file(File.expand_path("~/.eyrc")).should == {"api_token" => "asdf"}
    end
  end

end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
engineyard-1.4.7 spec/engineyard/cli/api_spec.rb
engineyard-1.4.6 spec/engineyard/cli/api_spec.rb
engineyard-1.4.5 spec/engineyard/cli/api_spec.rb
engineyard-1.4.4 spec/engineyard/cli/api_spec.rb
engineyard-1.4.3 spec/engineyard/cli/api_spec.rb
engineyard-1.4.2 spec/engineyard/cli/api_spec.rb
engineyard-1.4.1 spec/engineyard/cli/api_spec.rb
engineyard-1.4.0 spec/engineyard/cli/api_spec.rb
engineyard-1.3.33 spec/engineyard/cli/api_spec.rb
engineyard-1.3.32 spec/engineyard/cli/api_spec.rb
engineyard-1.3.31 spec/engineyard/cli/api_spec.rb
engineyard-1.3.30 spec/engineyard/cli/api_spec.rb
engineyard-1.3.29 spec/engineyard/cli/api_spec.rb
engineyard-1.3.28 spec/engineyard/cli/api_spec.rb
engineyard-1.3.25 spec/engineyard/cli/api_spec.rb
engineyard-1.3.22 spec/engineyard/cli/api_spec.rb
engineyard-1.3.21 spec/engineyard/cli/api_spec.rb
engineyard-1.3.20 spec/engineyard/cli/api_spec.rb
engineyard-1.3.19 spec/engineyard/cli/api_spec.rb
engineyard-1.3.18 spec/engineyard/cli/api_spec.rb