Skip to content

Commit f201035

Browse files
committed
Notify user of error and that examples are not run.
1 parent 1cf25c7 commit f201035

File tree

5 files changed

+49
-5
lines changed

5 files changed

+49
-5
lines changed

lib/guard/rspec/notifier.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ def notify(summary)
1818
priority: priority)
1919
end
2020

21-
def notify_failure
21+
def notify_failure(failure_message = 'Failed')
2222
return unless options[:notification]
23-
Guard::Compat::UI.notify("Failed",
23+
Guard::Compat::UI.notify(failure_message,
2424
title: @options[:title],
2525
image: :failed,
2626
priority: 2)

lib/guard/rspec/rspec_process.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ def all_green?
2222
exit_code.zero?
2323
end
2424

25+
# Returns true if there is an error AND examples are not run.
26+
def error_and_examples_not_run?
27+
error = "error occurred outside of examples"
28+
summary_regexp = %r{0 examples, 0 failures( \((\d+) #{error}\))?}
29+
results.summary.match?(summary_regexp)
30+
end
31+
2532
private
2633

2734
def _run

lib/guard/rspec/runner.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,18 @@ def _really_run(cmd, options)
6464

6565
process = RSpecProcess.new(cmd, file, options)
6666
results = process.results
67-
6867
inspector.failed(results.failed_paths)
69-
notifier.notify(results.summary)
70-
_open_launchy
7168

7269
all_green = process.all_green?
70+
71+
# Notify user of error and that examples are not run.
72+
if process.error_and_examples_not_run?
73+
notifier.notify_failure('Error/s occurred and examples are not run.')
74+
else
75+
notifier.notify(results.summary)
76+
end
77+
78+
_open_launchy
7379
return yield all_green if block_given?
7480
all_green
7581
end

spec/lib/guard/rspec/rspec_process_spec.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,18 @@
6464
context "with the failure code for normal test failures" do
6565
let(:exit_code) { Guard::RSpec::Command::FAILURE_EXIT_CODE }
6666

67+
before do
68+
summary = '2 examples, 1 failure'
69+
allow(results).to receive(:summary).and_return(summary)
70+
end
71+
6772
it "fails" do
6873
expect { subject }.to_not raise_error
6974
end
7075

7176
it { is_expected.to_not be_all_green }
77+
78+
it { is_expected.to_not be_error_and_examples_not_run }
7279
end
7380

7481
context "with no failures" do
@@ -148,5 +155,18 @@
148155
subject
149156
end
150157
end
158+
159+
context "with error outside examples" do
160+
let(:exit_code) { 2 }
161+
162+
before do
163+
summary = '0 examples, 0 failures, 1 error occurred outside of examples'
164+
allow(results).to receive(:summary).and_return(summary)
165+
end
166+
167+
it { is_expected.to_not be_all_green }
168+
169+
it { is_expected.to be_error_and_examples_not_run }
170+
end
151171
end
152172
end

spec/lib/guard/rspec/runner_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
allow(results).to receive(:summary).and_return("Summary")
2626
allow(results).to receive(:failed_paths).and_return([])
2727

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

343+
it "notifies that examples are not run" do
344+
allow(process).to receive(:all_green?).and_return(false)
345+
allow(process).to receive(:error_and_examples_not_run?).and_return(true)
346+
347+
expect(notifier).to receive(:notify_failure)
348+
.with(/Error\/s occurred and examples are not run./)
349+
350+
runner.run(paths)
351+
end
352+
342353
describe "return value" do
343354
subject { runner.run(paths) }
344355

0 commit comments

Comments
 (0)