Skip to content

Commit

Permalink
Notify user of error and that examples are not run.
Browse files Browse the repository at this point in the history
  • Loading branch information
wnuqui committed Jul 6, 2017
1 parent 1cf25c7 commit b5cce3e
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/guard/rspec/notifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions lib/guard/rspec/rspec_process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 9 additions & 3 deletions lib/guard/rspec/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions spec/lib/guard/rspec/rspec_process_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Up @@ -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)
Expand Down Expand Up @@ -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) }

Expand Down

0 comments on commit b5cce3e

Please sign in to comment.