Sha256: b624a24cd0630a4ed3935c436d706920b61de09134605fa5b2a4cbe6c69276e9

Contents?: true

Size: 1.54 KB

Versions: 13

Compression:

Stored size: 1.54 KB

Contents

require 'spec_helper'
require 'generators/jax/all'

describe Jax::Plugin::Credentials do
  def shell
    @shell ||= GenSpec::Shell.new
  end
  
  subject do
    Jax::Plugin::Credentials.new :home => local("."), :shell => shell
  end
  
  it "with new account" do
    shell.input.stub!(:gets).and_return 'missing@gmail.com', 'password', 'password'
    subject.api_key.should == "WXTzIXC2ODdbLAyvVL9p"
  end
  
  context "with missing config file and valid existing credentials" do
    before :each do
      shell.input.stub!(:gets).and_return 'sinisterchipmunk@gmail.com', 'password'
    end
    
    it "should return api key" do
      subject.api_key.should == "WXTzIXC2ODdbLAyvVL9p"
    end
    
    it "should create config file" do
      subject.api_key
      File.should exist(local "./.jax")
    end
  end
  
  it "with missing config file and invalid credentials for an existing account" do
    shell.input.stub!(:gets).and_return 'missing@gmail.com', 'invalid'
    proc { subject.api_key }.should raise_error(RuntimeError)
  end
  
  it "with missing api key" do
    shell.input.stub!(:gets).and_return 'missing@gmail.com', 'password', 'password'
    subject.api_key
    shell.output.string.should =~ /email/i
  end
  
  it "with api key" do
    create_file(".jax") { |f| f.print 'api_key: "1234"' }
    subject.api_key.should == "1234"
  end
  
  it "default home" do
    Jax::Plugin::Credentials.new.home.should == Thor::Util.user_home
  end
  
  it "override home" do
    Jax::Plugin::Credentials.new(:home => ".").home.should == File.expand_path(".")
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
jax-2.0.12 spec/lib/jax/commands/plugin_manager/credentials_spec.rb
jax-2.0.11 spec/lib/jax/commands/plugin_manager/credentials_spec.rb
jax-2.0.10 spec/lib/jax/commands/plugin_manager/credentials_spec.rb
jax-2.0.9 spec/lib/jax/commands/plugin_manager/credentials_spec.rb
jax-2.0.8 spec/lib/jax/commands/plugin_manager/credentials_spec.rb
jax-2.0.7 spec/lib/jax/commands/plugin_manager/credentials_spec.rb
jax-2.0.6 spec/lib/jax/commands/plugin_manager/credentials_spec.rb
jax-2.0.5 spec/lib/jax/commands/plugin_manager/credentials_spec.rb
jax-2.0.4 spec/lib/jax/commands/plugin_manager/credentials_spec.rb
jax-2.0.3 spec/lib/jax/commands/plugin_manager/credentials_spec.rb
jax-2.0.2 spec/lib/jax/commands/plugin_manager/credentials_spec.rb
jax-2.0.1 spec/lib/jax/commands/plugin_manager/credentials_spec.rb
jax-2.0.0 spec/lib/jax/commands/plugin_manager/credentials_spec.rb