spec/shelly/cli/main_spec.rb in shelly-0.1.4.pre vs spec/shelly/cli/main_spec.rb in shelly-0.1.4.pre2

- old
+ new

@@ -54,22 +54,15 @@ out = IO.popen("bin/shelly --debug").read.strip out.should == expected.strip end it "should display options in help for logs" do - expected = <<-OUT -Usage: - shelly logs - -Options: - -c, [--cloud=CLOUD] # Specify cloud - [--debug] # Show debug information - -Show latest application logs -OUT out = IO.popen("bin/shelly help logs").read.strip - out.should == expected.strip + out.should include("-c, [--cloud=CLOUD] # Specify cloud") + out.should include("-n, [--limit=N] # Amount of messages to show") + out.should include("-f, [--tail] # Show new logs automatically") + out.should include("[--debug] # Show debug information") end end describe "#register" do before do @@ -1068,19 +1061,20 @@ Shelly::User.stub(:new).and_return(@user) @client.stub(:apps).and_return([{"code_name" => "foo-production"}, {"code_name" => "foo-staging"}]) @app = Shelly::App.new Shelly::App.stub(:new).and_return(@app) + @sample_logs = {"entries" => [['app1', 'log1'], ['app1', 'log2']]} end it "should ensure user has logged in" do hooks(@main, :logs).should include(:logged_in?) end # multiple_clouds is tested in main_spec.rb in describe "#start" block it "should ensure multiple_clouds check" do - @client.stub(:application_logs).and_return(["log1"]) + @client.stub(:application_logs).and_return(@sample_logs) @main.should_receive(:multiple_clouds).and_return(@app) invoke(@main, :logs) end it "should exit if user doesn't have access to clouds in Cloudfile" do @@ -1089,27 +1083,29 @@ $stdout.should_receive(:puts). with(red "You have no access to 'foo-production' cloud defined in Cloudfile") lambda { invoke(@main, :logs) }.should raise_error(SystemExit) end + it "should exit if user requested too many log lines" do + exception = Shelly::Client::APIException.new({}, 416) + @client.stub(:application_logs).and_raise(exception) + $stdout.should_receive(:puts). + with(red "You have requested too many log messages. Try a lower number.") + lambda { invoke(@main, :logs) }.should raise_error(SystemExit) + end + it "should show logs for the cloud" do - @client.stub(:application_logs).and_return(["log1"]) - $stdout.should_receive(:puts).with(green "Cloud foo-production:") - $stdout.should_receive(:puts).with(green "Instance 1:") - $stdout.should_receive(:puts).with("log1") + @client.stub(:application_logs).and_return(@sample_logs) + $stdout.should_receive(:puts).with(" app1 | log1\n") + $stdout.should_receive(:puts).with(" app1 | log2\n") invoke(@main, :logs) end - context "multiple instances" do - it "should show logs from each instance" do - @client.stub(:application_logs).and_return(["log1", "log2"]) - $stdout.should_receive(:puts).with(green "Cloud foo-production:") - $stdout.should_receive(:puts).with(green "Instance 1:") - $stdout.should_receive(:puts).with("log1") - $stdout.should_receive(:puts).with(green "Instance 2:") - $stdout.should_receive(:puts).with("log2") - invoke(@main, :logs) - end + it "should show requested amount of logs" do + @client.should_receive(:application_logs). + with("foo-production", {:limit => 2}).and_return(@sample_logs) + @main.options = {:limit => 2} + invoke(@main, :logs) end end describe "#rake" do before do