Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output stdout immediately #7

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ Enable or disable the recursive directory mocha option

Paths for run all specs

* `:globals # default => []`

Globals to ignore when performing global leak detection

* `:mocha_bin`

Specify the path to the jasmine-node binary that will execute your specs.
Expand Down
5 changes: 3 additions & 2 deletions lib/guard/mocha_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ class MochaNode < Guard
:coffeescript => true,
:livescript => false,
:verbose => true,
:reporter => "spec",
:reporter => "spec",
:color => true,
:recursive => true,
:require => nil,
:paths_for_all_specs => %w(spec)
:paths_for_all_specs => %w(spec),
:globals => []
}

autoload :Runner, "guard/mocha_node/runner"
Expand Down
10 changes: 10 additions & 0 deletions lib/guard/mocha_node/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ def self.command_line_options
options << "-C"
end

if @options[:globals] and not @options[:globals].empty?
options << "--globals"
options << @options[:globals].join(',')
end

if @options[:reporter]
options << "--reporter"
options << @options[:reporter]
end

# puts "---- printing the options"
# puts options
options
Expand Down
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
12 changes: 10 additions & 2 deletions spec/lib/mocha_node_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,17 @@
end

it "sets :require option to nil" do
guard.options[:require].should_not be
guard.options[:require].should_not be
end

it "sets :paths_for_all_specs option to ['spec']" do
guard.options[:paths_for_all_specs].should eql ['spec']
end

it "sets :globals option to []" do
guard.options[:globals].should eql []
end

it "is passing" do
guard.should be_passing
end
Expand All @@ -87,7 +91,8 @@
:color => false,
:recursive => false,
:require => "should",
:paths_for_all_specs => %w(test)
:paths_for_all_specs => %w(test),
:globals => ['Foo']
}) }

it "sets the path to mocha bin" do
Expand Down Expand Up @@ -133,6 +138,9 @@
it "sets the :paths_for_all_specs option" do
guard.options[:paths_for_all_specs].should eql ['test']
end
it "sets the :globals option" do
guard.options[:globals].should eql ['Foo']
end
end
end

Expand Down
40 changes: 40 additions & 0 deletions spec/lib/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,46 @@
end
end

context "and globals option is set" do
it "passes the --globals option to mocha node" do
Open3.should_receive(:popen3) do |*args|
args.should include("--globals", "Foo")
# ensure ordering
args[args.index("--globals") + 1].should eql("Foo")
end
runner.run(some_paths, options.merge({ :globals => ['Foo']}))
end
end

context "and globals option is empty" do
it "does not pass the --globals option to mocha node" do
Open3.should_receive(:popen3) do |*args|
args.should_not include "--globals"
end
runner.run(some_paths, options.merge({ :globals => []}))
end
end

context "and reporter option is set" do
it "passes the --reporter option to mocha node" do
Open3.should_receive(:popen3) do |*args|
args.should include("--reporter", "Foo")
# ensure ordering
args[args.index("--reporter") + 1].should eql("Foo")
end
runner.run(some_paths, options.merge({ :reporter => 'Foo' }))
end
end

context "and reporter option is not set" do
it "does not pass the --reporter option to mocha node" do
Open3.should_receive(:popen3) do |*args|
args.should_not include "--reporter"
end
runner.run(some_paths, options)
end
end

context "and recursive option is true" do
it "passes the --recursive option to mocha node" do
Open3.should_receive(:popen3) do |*args|
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