Skip to content

Commit

Permalink
stream stdout IO immediately
Browse files Browse the repository at this point in the history
Previously guard-mocha-node was buffering the output from mocha,
resulting in no output shown to the user until mocha had completed. Now
stdout at least streams out immediately.
  • Loading branch information
neerolyte committed Apr 21, 2013
1 parent a231151 commit 8e1a5c0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions lib/guard/mocha_node/spec_state.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ def update(run_paths = [], options = {})
@io = Runner.run(@run_paths, options)
@stdout = @io[STDOUT]
@stderr = @io[STDERR]
@exitstatus = @io[THREAD].value rescue ERROR_CODE
@stdout.lines { |line| print line if !line.strip.empty? }
# stream stdout immediately
until @stdout.eof?
line = @stdout.gets
print line if !line.strip.empty?
end
@stderr.lines { |line| print line }
@exitstatus = @io[THREAD].value rescue ERROR_CODE
close_io
update_passed_and_fixed
update_failing_paths
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/spec_state_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
describe "#update" do
let(:io) { [
double("stdin", :close => true),
double("stdout", :close => true, :lines => []),
double("stdout", :close => true, :lines => [], :eof? => true),
double("stderr", :close => true, :lines => []),
double("thread", :value => 0)
] }
Expand Down

1 comment on commit 8e1a5c0

@ashmoran
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was having trouble using Mocha's progress reporter and started to file an issue before I realised I might be putting it in the wrong repo: rhuelga#8 (in summary, this commit helps stream line-based reporters, but still buffers the whole of of a character-based reporter like progress before writing it).

Please sign in to comment.