Sha256: e6a531d2f0686fc768e978a55f7af4d4ea351711d8ced0e9e78faab4809cf58f

Contents?: true

Size: 1.84 KB

Versions: 2

Compression:

Stored size: 1.84 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, 'config.yml') }
  let(:options) { { basedir: configdir, workspace: 'default' } }
  let(:input) { StringIO.new }
  let(:output) { StringIO.new }

  before { FileUtils.mkdir_p configdir unless Dir.exist?(configdir) }
  after { FileUtils.rm configfile if File.exist?(configfile) }

  describe '.new' do
    context 'when there is already config files created,' do
      let(:configvars) { { 'use_colors' => true, 'workspace' => 'default' } }
      before { File.open(configfile, 'w') { |f| f.puts YAML.dump(configvars) } }
      let(:config) { Hackpad::Cli::Config.new(options) }
      it {
        expect(config.workspace).to eq 'default'
      }
    end
    context 'when there is no config files created,' do
      before { input.stub(:gets).and_return('y', 'default') }
      let(:config) { Hackpad::Cli::Config.new(options, input, output) }
      it {
        expect(config.workspace).to eq 'default'
      }
    end
  end

  describe '.patch_1' do
    let(:oldconfigfile) { File.join(configdir, 'default.yml') }
    let(:workspacefile) { File.join(configdir, 'default', 'config.yml') }
    let(:oldconfigvars) { { 'client_id' => '123', 'secret' => 'toto', 'site' => 'http://example.com' } }
    before { File.open(oldconfigfile, 'w') { |f| f.puts YAML.dump(oldconfigvars) } }
    before { input.stub(:gets).and_return('y', 'default') }
    after { FileUtils.rm oldconfigfile if File.exist?(oldconfigfile) }
    after { FileUtils.rm workspacefile if File.exist?(workspacefile) }
    it do
      Hackpad::Cli::Config.new(options, input, output)
      expect(File.exist? oldconfigfile).to be false
      expect(File.exist? workspacefile).to be true
    end
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hackpad-cli-0.1.4 spec/lib/hackpad/cli/config_spec.rb
hackpad-cli-0.1.3 spec/lib/hackpad/cli/config_spec.rb