Skip to content

Commit

Permalink
Merge branch 'first_failure'
Browse files Browse the repository at this point in the history
Closes twe4ked#7.
  • Loading branch information
twe4ked committed Apr 27, 2013
2 parents 46485b7 + 015aead commit 59012a5
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/nc_first_fail.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require 'nc'

class NcFirstFail < Nc
def example_failed(example)
if @failed_examples.size == 0
name = File.basename(File.expand_path '.')
say "\u26D4 #{name}: Failure", "#{example.metadata[:full_description]}\n#{example.exception}"
end
super
end

def dump_summary(duration, example_count, failure_count, pending_count)
super if failure_count == 0
end
end
32 changes: 32 additions & 0 deletions spec/nc_first_fail_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require 'nc_first_fail'

describe NcFirstFail do
let(:formatter) { NcFirstFail.new(StringIO.new) }
let(:current_dir) { File.basename(File.expand_path '.') }
let(:example) { double 'example' }
let(:example2) { double 'example2' }

let(:failure) { "\u26D4" }
let(:exception) { 'exception' }
let(:description) { 'description' }

before do
example.should_receive(:metadata).any_number_of_times.and_return({:full_description => description})
example.should_receive(:exception).any_number_of_times.and_return(exception)
end

it 'notifies the first failure only' do
TerminalNotifier.should_receive(:notify).with("#{description}\n#{exception}",
:title => "#{failure} #{current_dir}: Failure"
)

formatter.example_failed(example)
formatter.example_failed(example2)
end

it "doesn't notify in the end if there has been any failures" do
TerminalNotifier.should_not_receive(:notify)

formatter.dump_summary(0.0001, 2, 1, 0)
end
end

0 comments on commit 59012a5

Please sign in to comment.