Skip to content

Commit 47d7387

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

File tree

4 files changed

+29
-5
lines changed

4 files changed

+29
-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: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ 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+
example_count, failure_count, pending_count =
28+
_parse_summary(results.summary)
29+
30+
!all_green? && \
31+
example_count == 0 && failure_count == 0 && pending_count == 0
32+
end
33+
2534
private
2635

2736
def _run
@@ -85,6 +94,14 @@ def _warn_unless_absolute_path(formatter_tmp_file)
8594
Compat::UI.warning(format(msg, formatter_tmp_file.inspect))
8695
end
8796

97+
def _parse_summary(summary)
98+
summary_regexp = /(\d+) examples, (\d+) failures( \((\d+) pending\))?/
99+
summary.match(summary_regexp) do |m|
100+
return m[1].to_i, m[2].to_i, m[4].to_i
101+
end
102+
[0, 0, 0]
103+
end
104+
88105
attr_reader :command
89106
attr_reader :exit_code
90107
attr_reader :formatter_tmp_file

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/runner_spec.rb

Lines changed: 1 addition & 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)

0 commit comments

Comments
 (0)