Skip to content

Commit

Permalink
Merge pull request #337 from sidonath/fix-runner-result
Browse files Browse the repository at this point in the history
Fix return value of the runner
  • Loading branch information
e2 committed Jul 14, 2015
2 parents 36f5b10 + 639c831 commit 0a557c1
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/guard/rspec/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ def run(paths)
return true if paths.empty?
Compat::UI.info("Running: #{paths.join(' ')}", reset: true)
_run(paths, options) do |all_green|
run_all if options[:all_after_pass] && all_green
next false unless all_green
next true unless options[:all_after_pass]
run_all
end
end

Expand All @@ -53,7 +55,6 @@ def _run(paths, options, &block)
fail NoCmdOptionError unless options[:cmd]
command = Command.new(paths, options)
_really_run(command, options, &block)
true
rescue RSpecProcess::Failure, NoCmdOptionError => ex
Compat::UI.error(ex.to_s)
notifier.notify_failure
Expand All @@ -71,7 +72,12 @@ def _really_run(cmd, options)
notifier.notify(results.summary)
_open_launchy

yield process.all_green? if block_given?
all_green = process.all_green?
if block_given?
yield all_green
else
all_green
end
end

def _open_launchy
Expand Down
44 changes: 44 additions & 0 deletions spec/lib/guard/rspec/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,20 @@
expect(notifier).to have_received(:notify_failure)
end
end

describe "return value" do
subject { runner.run_all }

it { is_expected.to be true }

context "when process is not all green" do
before do
allow(process).to receive(:all_green?).and_return(false)
end

it { is_expected.to be false }
end
end
end

describe "#run" do
Expand Down Expand Up @@ -284,5 +298,35 @@
expect(notifier).to receive(:notify_failure)
runner.run(paths)
end

describe "return value" do
subject { runner.run(paths) }

it { is_expected.to be true }

context "with all_after_pass option" do
let(:options) do
{ cmd: "rspec", all_after_pass: true, run_all: {}, spec_paths: paths }
end

it { is_expected.to be true }

describe "when all tests fail" do
before do
allow(process).to receive(:all_green?).and_return(true, false)
end

it { is_expected.to be false }
end
end

context "when process is not all green" do
before do
allow(process).to receive(:all_green?).and_return(false)
end

it { is_expected.to be false }
end
end
end
end

0 comments on commit 0a557c1

Please sign in to comment.