spec/lib/appsignal/cli_spec.rb in appsignal-2.0.3 vs spec/lib/appsignal/cli_spec.rb in appsignal-2.0.4

- old
+ new

@@ -1,76 +1,56 @@ require 'appsignal/cli' describe Appsignal::CLI do - let(:out_stream) { StringIO.new } + let(:out_stream) { std_stream } + let(:output) { out_stream.read } let(:cli) { Appsignal::CLI } - before do - Dir.stub(:pwd => project_fixture_path) - cli.options = {:environment => 'production'} - end - around do |example| - capture_stdout(out_stream) { example.run } - end + before { Dir.stub(:pwd => project_fixture_path) } - describe "#config" do - subject { cli.config } - - it { should be_instance_of(Appsignal::Config) } - its(:valid?) { should be_true } - end - it "should print the help with no arguments, -h and --help" do [nil, '-h', '--help'].each do |arg| - lambda { - cli.run([arg].compact) - }.should raise_error(SystemExit) + expect do + capture_stdout(out_stream) do + cli.run([arg].compact) + end + end.to raise_error(SystemExit) - out_stream.string.should include 'appsignal <command> [options]' - out_stream.string.should include \ + expect(output).to include 'appsignal <command> [options]' + expect(output).to include \ 'Available commands: demo, diagnose, install, notify_of_deploy' end end it "should print the version with -v and --version" do ['-v', '--version'].each do |arg| - lambda { - cli.run([arg]) - }.should raise_error(SystemExit) + expect do + capture_stdout(out_stream) do + cli.run([arg]) + end + end.to raise_error(SystemExit) - out_stream.string.should include 'AppSignal' - out_stream.string.should include '.' + expect(output).to include 'AppSignal' + expect(output).to include '.' end end it "should print a notice if a command does not exist" do - lambda { + expect do + capture_stdout(out_stream) do cli.run(['nonsense']) - }.should raise_error(SystemExit) + end + end.to raise_error(SystemExit) - out_stream.string.should include "Command 'nonsense' does not exist, run "\ + expect(output).to include "Command 'nonsense' does not exist, run "\ "appsignal -h to see the help" end describe "diagnose" do it "should call Appsignal::Diagnose.install" do Appsignal::CLI::Diagnose.should_receive(:run) cli.run([ 'diagnose' - ]) - end - end - - describe "install" do - it "should call Appsignal::Install.install" do - Appsignal::CLI::Install.should_receive(:run).with( - 'api-key', - instance_of(Appsignal::Config) - ) - - cli.run([ - 'install', - 'api-key' ]) end end end