Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Commit d729301

Browse files
authored
Merge pull request #2421 from rspec/turn-summary-line-red-if-any-error-outside-of-examples
Turn summary line red when there's any error occured outside of examples
2 parents 484157b + c0760ac commit d729301

File tree

2 files changed

+108
-8
lines changed

2 files changed

+108
-8
lines changed

lib/rspec/core/notifications.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ def totals_line
336336
# specific colors.
337337
# @return [String] A colorized results line.
338338
def colorized_totals_line(colorizer=::RSpec::Core::Formatters::ConsoleCodes)
339-
if failure_count > 0
339+
if failure_count > 0 || errors_outside_of_examples_count > 0
340340
colorizer.wrap(totals_line, RSpec.configuration.failure_color)
341341
elsif pending_count > 0
342342
colorizer.wrap(totals_line, RSpec.configuration.pending_color)

spec/rspec/core/notifications_spec.rb

Lines changed: 107 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
require 'rspec/core/notifications'
22

3+
# ANSI codes aren't easy to read in failure output, so use tags instead
4+
class TagColorizer
5+
def self.wrap(text, code_or_symbol)
6+
"<#{code_or_symbol}>#{text}</#{code_or_symbol}>"
7+
end
8+
end
9+
310
RSpec.describe "FailedExampleNotification" do
411
include FormatterSupport
512

@@ -32,13 +39,6 @@ def dedent(string)
3239
string.gsub(/^ +\|/, '')
3340
end
3441

35-
# ANSI codes aren't easy to read in failure output, so use tags instead
36-
class TagColorizer
37-
def self.wrap(text, code_or_symbol)
38-
"<#{code_or_symbol}>#{text}</#{code_or_symbol}>"
39-
end
40-
end
41-
4242
context "when the exception is a MultipleExpectationsNotMetError" do
4343
RSpec::Matchers.define :fail_with_description do |desc|
4444
match { false }
@@ -357,3 +357,103 @@ module RSpec::Core::Notifications
357357
end
358358
end
359359
end
360+
361+
module RSpec::Core::Notifications
362+
RSpec.describe SummaryNotification do
363+
include FormatterSupport
364+
365+
subject(:notification) do
366+
summary_notification(
367+
duration,
368+
examples,
369+
failed_examples,
370+
pending_examples,
371+
load_time,
372+
errors_outside_of_examples_count
373+
)
374+
end
375+
376+
let(:duration) do
377+
1.23
378+
end
379+
380+
let(:examples) do
381+
[
382+
new_example(:status => :passed),
383+
new_example(:status => :passed)
384+
]
385+
end
386+
387+
let(:failed_examples) do
388+
examples.select { |example| example.execution_result.status == :failed }
389+
end
390+
391+
let(:pending_examples) do
392+
examples.select { |example| example.execution_result.status == :pending }
393+
end
394+
395+
let(:load_time) do
396+
0.1
397+
end
398+
399+
let(:errors_outside_of_examples_count) do
400+
0
401+
end
402+
403+
describe '#fully_formatted' do
404+
subject(:fully_formatted) do
405+
notification.fully_formatted(TagColorizer)
406+
end
407+
408+
context 'when all examples are passed' do
409+
let(:examples) do
410+
[
411+
new_example(:status => :passed),
412+
new_example(:status => :passed)
413+
]
414+
end
415+
416+
it 'turns the summary line green' do
417+
expect(fully_formatted).to include('<green>2 examples, 0 failures</green>')
418+
end
419+
end
420+
421+
context "when there're a pending example and no failed example" do
422+
let(:examples) do
423+
[
424+
new_example(:status => :passed),
425+
new_example(:status => :pending)
426+
]
427+
end
428+
429+
it 'turns the summary line yellow' do
430+
expect(fully_formatted).to include('<yellow>2 examples, 0 failures, 1 pending</yellow>')
431+
end
432+
end
433+
434+
context "when there're a pending example and a failed example" do
435+
let(:examples) do
436+
[
437+
new_example(:status => :passed),
438+
new_example(:status => :pending),
439+
new_example(:status => :failed)
440+
]
441+
end
442+
443+
it 'turns the summary line red' do
444+
expect(fully_formatted).to include('<red>3 examples, 1 failure, 1 pending</red>')
445+
end
446+
end
447+
448+
context "when there's an error outside of examples" do
449+
let(:errors_outside_of_examples_count) do
450+
1
451+
end
452+
453+
it 'turns the summary line red' do
454+
expect(fully_formatted).to include('<red>2 examples, 0 failures, 1 error occurred outside of examples</red>')
455+
end
456+
end
457+
end
458+
end
459+
end

0 commit comments

Comments
 (0)