spec/lib/hackpad/cli/config_spec.rb in hackpad-cli-0.0.7 vs spec/lib/hackpad/cli/config_spec.rb in hackpad-cli-0.1.0

- old
+ new

@@ -1,44 +1,45 @@ # encoding: utf-8 require 'spec_helper' -require "hackpad/cli/config" +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.exists?(configdir) + FileUtils.mkdir_p configdir unless Dir.exist?(configdir) end after :each do - FileUtils.rm configfile if File.exists? configfile + FileUtils.rm configfile if File.exist?(configfile) end - describe ".load" do - let(:config) { {'xx' => 'oo'} } + describe '.load' do + let(:config) { { 'xx' => 'oo' } } - context "when there is no config file," do - it "calls for setup" do - subject.stub(:setup).with(configfile) - File.open(configfile, "w") do |f| - f.write YAML::dump(config) + 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 + 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") + 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