Sha256: 14e8820374ae9c5e07be2b6c7abd7e54fffb62590d542e41fe659ac07e096dcd

Contents?: true

Size: 1.74 KB

Versions: 12

Compression:

Stored size: 1.74 KB

Contents

require 'spec_helper'
require 'engineyard/eyrc'

describe EY::EYRC do
  describe ".load" do
    it "looks for .eyrc in $EYRC if set" do
      EY::EYRC.load.path.should == Pathname.new(ENV['EYRC'])
    end

    it "looks for .eyrc in $HOME/.eyrc by default" do
      ENV.delete('EYRC')
      EY::EYRC.load.path.should == Pathname.new("~/.eyrc").expand_path
    end
  end

  describe ".new" do
    it "looks for eyrc in any passed file location" do
      EY::EYRC.new('/tmp/neweyrc').path.should == Pathname.new('/tmp/neweyrc')
    end
  end

  context "with a non-existing .eyrc file" do
    it "has nil api_token" do
      File.exists?("/tmp/nonexistant").should be_false
      eyrc = EY::EYRC.new('/tmp/nonexistant')
      eyrc.exist?.should be_false
      eyrc.api_token.should be_nil
    end
  end

  context "saving api token" do
    before do
      EY::EYRC.load.api_token = 'abcd'
    end

    it "exists" do
      EY::EYRC.load.exist?.should be_true
    end

    it "recalls the api_token" do
      EY::EYRC.load.api_token.should == 'abcd'
    end

    it "writes the api_token to api_token: .eyrc" do
      read_yaml(ENV['EYRC']).should == {"api_token" => "abcd"}
    end
  end

  context "file contains other random info" do
    before do
      # contains legacy endpoint behavior, no longer supported, but we won't be destructive.
      write_yaml({"api_token" => "1234", "http://localhost/" => {"api_token" => "5678"}}, ENV['EYRC'])
      EY::EYRC.load.api_token = 'abcd' # overwrites 1234
    end

    it "recalls the api_token" do
      EY::EYRC.load.api_token.should == 'abcd'
    end

    it "maintains other random info in the file" do
      read_yaml(ENV['EYRC']).should == {"api_token" => "abcd", "http://localhost/" => {"api_token" => "5678"}}
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
engineyard-1.4.20 spec/engineyard/eyrc_spec.rb
engineyard-1.4.19 spec/engineyard/eyrc_spec.rb
engineyard-1.4.18 spec/engineyard/eyrc_spec.rb
engineyard-1.4.17 spec/engineyard/eyrc_spec.rb
engineyard-1.4.16 spec/engineyard/eyrc_spec.rb
engineyard-1.4.15 spec/engineyard/eyrc_spec.rb
engineyard-1.4.14 spec/engineyard/eyrc_spec.rb
engineyard-1.4.13 spec/engineyard/eyrc_spec.rb
engineyard-1.4.11 spec/engineyard/eyrc_spec.rb
engineyard-1.4.10 spec/engineyard/eyrc_spec.rb
engineyard-1.4.9 spec/engineyard/eyrc_spec.rb
engineyard-1.4.8 spec/engineyard/eyrc_spec.rb