Sha256: 33957b7dc49b0377bdc8deaa5b2d4d95b809dc3e43b3cd7161c240b30f15bc61

Contents?: true

Size: 1.28 KB

Versions: 1

Compression:

Stored size: 1.28 KB

Contents

# encoding: utf-8

require 'spec_helper'
require 'hackpad/cli/config'

describe Hackpad::Cli::Config do

  let(:configdir) { File.expand_path('../../../../files', __FILE__) }
  let(:configfile) { File.join(configdir, 'default.yml') }
  let(:options) { { configdir: configdir, workspace: 'default' } }

  before :each do
    FileUtils.mkdir_p configdir unless Dir.exist?(configdir)
  end

  after :each do
    FileUtils.rm configfile if File.exist?(configfile)
  end

  describe '.load' do
    let(:config) { { 'xx' => 'oo' } }

    context 'when there is no config file,' do
      it 'calls for setup' do
        Dir.stub(:exists?).and_return false
        subject.stub(:setup).with(configfile, STDIN, STDOUT)
        File.open(configfile, 'w') do |f|
          f.write YAML.dump(config)
        end
        expect(subject.load options).to eq config
      end
    end

  end

  describe '.setup' do
    context 'when normal input is provided,' do
      let(:input) { StringIO.new }
      let(:output) { StringIO.new }
      it 'handles setup interactively' do
        input.stub(:gets).and_return('client_id', 'secret', 'site')
        subject.send :setup, configfile, input, output
        expect(File.read configfile).to eq "---\nclient_id: client_id\nsecret: secret\nsite: site\n"
      end
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hackpad-cli-0.1.0 spec/lib/hackpad/cli/config_spec.rb