spec/lib/hackpad/cli/client_spec.rb in hackpad-cli-0.1.2 vs spec/lib/hackpad/cli/client_spec.rb in hackpad-cli-0.1.3

- old
+ new

@@ -9,11 +9,11 @@ let(:configfile) { File.join(configdir, 'config.yml') } let(:workspacedir) { File.join(configdir, 'default') } let(:workspacefile) { File.join(workspacedir, 'config.yml') } let(:configvars) { { 'use_colors' => true, 'workspace' => 'default' } } let(:workspacevars) { { 'client_id' => '123', 'secret' => 'toto', 'site' => 'http://example.com' } } - let(:options) { { configdir: configdir, workspace: 'default' } } + let(:options) { { basedir: configdir, workspace: 'default' } } let(:format) { "%-20s %s\n" } let(:input) { StringIO.new } let(:output) { StringIO.new } before { FileUtils.mkdir_p configdir } before { FileUtils.mkdir_p workspacedir } @@ -47,13 +47,12 @@ before { FileUtils.mkdir_p workspacedir2 } before { File.open(workspacefile2, 'w') { |f| f.puts YAML.dump(workspacevars2) } } after { FileUtils.rm workspacefile2 if File.exist?(workspacefile2) } it do - expect(output).to receive(:printf).with(format, '> default', 'http://example.com') - expect(output).to receive(:printf).with(format, 'default2', 'http://2.example.com') client.workspaces + expect(output.string).to eq "> default http://example.com\ndefault2 http://2.example.com\n" end end describe '.default' do let(:client) { Hackpad::Cli::Client.new(options, input, output) } @@ -64,12 +63,12 @@ before { FileUtils.mkdir_p workspacedir2 } before { File.open(workspacefile2, 'w') { |f| f.puts YAML.dump(workspacevars2) } } after { FileUtils.rm workspacefile2 if File.exist?(workspacefile2) } it do - expect(output).to receive(:print).with("What workspace do you want to use as default from now on? \n> 0 default\n 1 default2\nChoose a number: [0] ") client.default + expect(output.string).to eq "What workspace do you want to use as default from now on? \n> 0 default\n 1 default2\nChoose a number: [0] " expect(YAML.load_file(configfile)['workspace']).to eq 'default2' end end describe '.stats' do @@ -77,14 +76,12 @@ before { Hackpad::Cli::Store.stub(:prepare) } before { Hackpad::Cli::Store.stub(:count_pads).and_return(12) } before { Hackpad::Cli::Store.stub(:last_refresh).and_return(timestamp) } let(:client) { Hackpad::Cli::Client.new(options, input, output) } it do - expect(output).to receive(:printf).with(format, 'Site', Paint[workspacevars['site'], :blue]) - expect(output).to receive(:printf).with(format, 'Cached Pads', 12) - expect(output).to receive(:printf).with(format, 'Last Refresh', timestamp) client.stats + expect(output.string).to eq "Site #{Paint[workspacevars['site'], :blue]}\nCached Pads 12\nLast Refresh #{timestamp}\n" end end describe '.search' do before { Hackpad::Cli::Api.stub(:prepare) } @@ -109,13 +106,12 @@ end end context 'when options sets urls to true,' do let(:client) { Hackpad::Cli::Client.new(options.merge(urls: true), input, output) } it do - expect(output).to receive(:puts).with("#{workspacevars['site']}/#{Paint['xxxxxx', :bold]} - #{Paint['xtitle', :yellow]}") - expect(output).to receive(:puts).with(" context #{Paint['x', :cyan, :bold]} context") client.search 'xxx' + expect(output.string).to eq "#{workspacevars['site']}/#{Paint['xxxxxx', :bold]} - #{Paint['xtitle', :yellow]}\n context #{Paint['x', :cyan, :bold]} context\n" end end end describe '.list' do @@ -195,20 +191,21 @@ before { pad.stub(:title).and_return('title1') } before { pad.stub(:chars).and_return(20) } before { pad.stub(:lines).and_return(2) } before { pad.stub(:guest_policy).and_return('open') } before { pad.stub(:moderated).and_return('false') } - before { pad.stub(:cached_at).and_return } + before { pad.stub(:cached_at).and_return('unknown') } it do expect(output).to receive(:printf).with(format, 'Id', Paint["123", :bold]) expect(output).to receive(:printf).with(format, 'Title', Paint['title1', :yellow]) expect(output).to receive(:printf).with(format, 'URI', "#{workspacevars['site']}/123") expect(output).to receive(:printf).with(format, 'Chars', '20') expect(output).to receive(:printf).with(format, 'Lines', '2') expect(output).to receive(:printf).with(format, 'Guest Policy', 'open') expect(output).to receive(:printf).with(format, 'Moderated', 'false') expect(output).to receive(:printf).with(format, 'Cached', 'unknown') client.info '123' + end end end