Skip to content

Guard::MochaNode buffers output of progress formatter #8

@ashmoran

Description

@ashmoran

I noticed that Guard::MochaNode works fine on line-based Mocha reporters (list, spec, etc) but that with single-line character-based reporters (dot, progress, etc), it buffers the entire line, which kinda defeats the purpose of these reporters.

After looking around I found the culprit is here: https://github.com/kanzeon/guard-mocha-node/blob/master/lib/guard/mocha_node/spec_state.rb#L24

I'm a little puzzled, because the gem version I've installed with Bundler has this on those lines:

# stream stdout immediately
until @stdout.eof?
  line = @stdout.gets
  print line if !line.strip.empty?
end

whereas the version in this repo has this:

@stdout.lines { |line| print line if !line.strip.empty? }

Is @neerolyte now pushing this gem to rubygems.org via https://github.com/neerolyte/guard-mocha-node/ ? If so, I don't have a way to report this issue directly, as he doesn't have issues enabled on his fork.

Anyway, I found a relatively easy fix to the problem, which is to print mocha's output one character at a time.

# stream stdout immediately
until @stdout.eof?
  output = @stdout.getc
  $stdout.putc output
end

Although that made me wonder, why is Guard::MochaNode separating the stdout and stderr output from mocha? Would there be a disadvantage of using Kernel#system instead of Open3.popen3 in the runner here: https://github.com/kanzeon/guard-mocha-node/blob/master/lib/guard/mocha_node/runner.rb#L27 - and just let mocha take responsibility for sequencing the output?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions