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

Notify user of error and that examples are not run #399

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Notify user of error and that examples are not run.
wnuqui authored and Wilfrido T. Nuqui Jr committed Jul 7, 2017
commit 7a2fd0686d74fbf510541244009d4de2f979263f
4 changes: 2 additions & 2 deletions lib/guard/rspec/notifier.rb
Original file line number Diff line number Diff line change
@@ -18,9 +18,9 @@ def notify(summary)
priority: priority)
end

def notify_failure
def notify_failure(failure_message = 'Failed')
return unless options[:notification]
Guard::Compat::UI.notify("Failed",
Guard::Compat::UI.notify(failure_message,
title: @options[:title],
image: :failed,
priority: 2)
7 changes: 7 additions & 0 deletions lib/guard/rspec/rspec_process.rb
Original file line number Diff line number Diff line change
@@ -22,6 +22,13 @@ def all_green?
exit_code.zero?
end

# Returns true if there is an error AND examples are not run.
def error_and_examples_not_run?
error = "error occurred outside of examples"
summary_regexp = /0 examples, 0 failures( \((\d+) #{error}\))?/
!!results.summary.match(summary_regexp)
end

private

def _run
12 changes: 9 additions & 3 deletions lib/guard/rspec/runner.rb
Original file line number Diff line number Diff line change
@@ -64,12 +64,18 @@ def _really_run(cmd, options)

process = RSpecProcess.new(cmd, file, options)
results = process.results

inspector.failed(results.failed_paths)
notifier.notify(results.summary)
_open_launchy

all_green = process.all_green?

# Notify user of error and that examples are not run.
if process.error_and_examples_not_run?
notifier.notify_failure('Error/s occurred and examples are not run.')
else
notifier.notify(results.summary)
end

_open_launchy
return yield all_green if block_given?
all_green
end
20 changes: 20 additions & 0 deletions spec/lib/guard/rspec/rspec_process_spec.rb
Original file line number Diff line number Diff line change
@@ -64,11 +64,18 @@
context "with the failure code for normal test failures" do
let(:exit_code) { Guard::RSpec::Command::FAILURE_EXIT_CODE }

before do
summary = '2 examples, 1 failure'
allow(results).to receive(:summary).and_return(summary)
end

it "fails" do
expect { subject }.to_not raise_error
end

it { is_expected.to_not be_all_green }

it { is_expected.to_not be_error_and_examples_not_run }
end

context "with no failures" do
@@ -148,5 +155,18 @@
subject
end
end

context "with error outside examples" do
let(:exit_code) { 2 }

before do
summary = '0 examples, 0 failures, 1 error occurred outside of examples'
allow(results).to receive(:summary).and_return(summary)
end

it { is_expected.to_not be_all_green }

it { is_expected.to be_error_and_examples_not_run }
end
end
end
11 changes: 11 additions & 0 deletions spec/lib/guard/rspec/runner_spec.rb
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@
allow(results).to receive(:summary).and_return("Summary")
allow(results).to receive(:failed_paths).and_return([])

allow(process).to receive(:error_and_examples_not_run?).and_return(false)
allow(Guard::RSpec::RSpecProcess).to receive(:new).and_return(process)
allow(process).to receive(:all_green?).and_return(true)
allow(process).to receive(:results).and_return(results)
@@ -339,6 +340,16 @@
runner.run(paths)
end

it "notifies that examples are not run" do
allow(process).to receive(:all_green?).and_return(false)
allow(process).to receive(:error_and_examples_not_run?).and_return(true)

expect(notifier).to receive(:notify_failure)
.with(%r{Error\/s occurred and examples are not run.})

runner.run(paths)
end

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