diff --git a/lib/guard/rspec/notifier.rb b/lib/guard/rspec/notifier.rb index 3154efc7..a6c52b3a 100644 --- a/lib/guard/rspec/notifier.rb +++ b/lib/guard/rspec/notifier.rb @@ -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) diff --git a/lib/guard/rspec/rspec_process.rb b/lib/guard/rspec/rspec_process.rb index d6772c45..827def58 100644 --- a/lib/guard/rspec/rspec_process.rb +++ b/lib/guard/rspec/rspec_process.rb @@ -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 = %r{0 examples, 0 failures( \((\d+) #{error}\))?} + !!results.summary.match(summary_regexp) + end + private def _run diff --git a/lib/guard/rspec/runner.rb b/lib/guard/rspec/runner.rb index 6a3e04ef..9a789bfa 100644 --- a/lib/guard/rspec/runner.rb +++ b/lib/guard/rspec/runner.rb @@ -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 diff --git a/spec/lib/guard/rspec/rspec_process_spec.rb b/spec/lib/guard/rspec/rspec_process_spec.rb index 69456f56..21a9d09e 100644 --- a/spec/lib/guard/rspec/rspec_process_spec.rb +++ b/spec/lib/guard/rspec/rspec_process_spec.rb @@ -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 diff --git a/spec/lib/guard/rspec/runner_spec.rb b/spec/lib/guard/rspec/runner_spec.rb index 17d0a077..17eac055 100644 --- a/spec/lib/guard/rspec/runner_spec.rb +++ b/spec/lib/guard/rspec/runner_spec.rb @@ -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) }