From 0df962ad00ecfdb2e013af69f44efe2056328d10 Mon Sep 17 00:00:00 2001 From: Pierre Flores Date: Thu, 13 Jun 2013 17:29:33 +0200 Subject: [PATCH 1/2] heroku logs now flushes immediatly when writing on not a terminal --- lib/heroku/helpers/log_displayer.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/heroku/helpers/log_displayer.rb b/lib/heroku/helpers/log_displayer.rb index 50ba95e13..7c1a43175 100644 --- a/lib/heroku/helpers/log_displayer.rb +++ b/lib/heroku/helpers/log_displayer.rb @@ -18,16 +18,17 @@ def display_logs heroku.read_logs(app, opts) do |chunk| unless chunk.empty? - if STDOUT.isatty && ENV.has_key?("TERM") + if $stdout.isatty && ENV.has_key?("TERM") display(colorize(chunk)) else display(chunk) + $stdout.flush end end end rescue Errno::EPIPE rescue Interrupt => interrupt - if STDOUT.isatty && ENV.has_key?("TERM") + if $stdout.isatty && ENV.has_key?("TERM") display("\e[0m") end raise(interrupt) From ea6a7063e2d5e9bef9160466c4bb4bb7c10e6ca7 Mon Sep 17 00:00:00 2001 From: Pierre Flores Date: Fri, 14 Jun 2013 11:47:08 +0200 Subject: [PATCH 2/2] Fixed IO testing : stubs now do something --- spec/heroku/command/logs_spec.rb | 10 ++-------- spec/spec_helper.rb | 4 +++- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/spec/heroku/command/logs_spec.rb b/spec/heroku/command/logs_spec.rb index edf15f541..2d21ec9db 100644 --- a/spec/heroku/command/logs_spec.rb +++ b/spec/heroku/command/logs_spec.rb @@ -24,25 +24,19 @@ end it "prettifies tty output" do - old_stdout_isatty = $stdout.isatty - stub($stdout).isatty.returns(true) - stderr, stdout = execute("logs") + stderr, stdout = execute("logs") { |sin, sout, serr| sout.stub!(:isatty).and_return(true) } stderr.should == "" stdout.should == <<-STDOUT \e[36m2011-01-01T00:00:00+00:00 app[web.1]:\e[0m test STDOUT - stub($stdout).isatty.returns(old_stdout_isatty) end it "does not use ansi if stdout is not a tty" do - old_stdout_isatty = $stdout.isatty - stub($stdout).isatty.returns(false) - stderr, stdout = execute("logs") + stderr, stdout = execute("logs") { |sin, sout, serr| sout.stub!(:isatty).and_return(false) } stderr.should == "" stdout.should == <<-STDOUT 2011-01-01T00:00:00+00:00 app[web.1]: test STDOUT - stub($stdout).isatty.returns(old_stdout_isatty) end it "does not use ansi if TERM is not set" do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 5bb152dcd..a84c499c6 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -40,7 +40,7 @@ def prepare_command(klass) command end -def execute(command_line) +def execute(command_line, &block) extend RR::Adapters::RRMethods args = command_line.split(" ") @@ -67,6 +67,8 @@ def tty? end end + yield $stdin, $stdout, $stderr if block_given? + begin object.send(method) rescue SystemExit