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

Fix return value of the runner #337

Merged
merged 1 commit into from
Jul 14, 2015
Merged
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
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