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

Turn summary line red when there's any error occured outside of examples #2421

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/rspec/core/notifications.rb
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def totals_line
# specific colors.
# @return [String] A colorized results line.
def colorized_totals_line(colorizer=::RSpec::Core::Formatters::ConsoleCodes)
if failure_count > 0
if failure_count > 0 || errors_outside_of_examples_count > 0
colorizer.wrap(totals_line, RSpec.configuration.failure_color)
elsif pending_count > 0
colorizer.wrap(totals_line, RSpec.configuration.pending_color)
Expand Down
114 changes: 107 additions & 7 deletions spec/rspec/core/notifications_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
require 'rspec/core/notifications'

# ANSI codes aren't easy to read in failure output, so use tags instead
class TagColorizer
def self.wrap(text, code_or_symbol)
"<#{code_or_symbol}>#{text}</#{code_or_symbol}>"
end
end

RSpec.describe "FailedExampleNotification" do
include FormatterSupport

Expand Down Expand Up @@ -32,13 +39,6 @@ def dedent(string)
string.gsub(/^ +\|/, '')
end

# ANSI codes aren't easy to read in failure output, so use tags instead
class TagColorizer
def self.wrap(text, code_or_symbol)
"<#{code_or_symbol}>#{text}</#{code_or_symbol}>"
end
end

context "when the exception is a MultipleExpectationsNotMetError" do
RSpec::Matchers.define :fail_with_description do |desc|
match { false }
Expand Down Expand Up @@ -357,3 +357,103 @@ module RSpec::Core::Notifications
end
end
end

module RSpec::Core::Notifications
RSpec.describe SummaryNotification do
include FormatterSupport

subject(:notification) do
summary_notification(
duration,
examples,
failed_examples,
pending_examples,
load_time,
errors_outside_of_examples_count
)
end

let(:duration) do
1.23
end

let(:examples) do
[
new_example(:status => :passed),
new_example(:status => :passed)
]
end

let(:failed_examples) do
examples.select { |example| example.execution_result.status == :failed }
end

let(:pending_examples) do
examples.select { |example| example.execution_result.status == :pending }
end

let(:load_time) do
0.1
end

let(:errors_outside_of_examples_count) do
0
end

describe '#fully_formatted' do
subject(:fully_formatted) do
notification.fully_formatted(TagColorizer)
end

context 'when all examples are passed' do
let(:examples) do
[
new_example(:status => :passed),
new_example(:status => :passed)
]
end

it 'turns the summary line green' do
expect(fully_formatted).to include('<green>2 examples, 0 failures</green>')
end
end

context "when there're a pending example and no failed example" do
let(:examples) do
[
new_example(:status => :passed),
new_example(:status => :pending)
]
end

it 'turns the summary line yellow' do
expect(fully_formatted).to include('<yellow>2 examples, 0 failures, 1 pending</yellow>')
end
end

context "when there're a pending example and a failed example" do
let(:examples) do
[
new_example(:status => :passed),
new_example(:status => :pending),
new_example(:status => :failed)
]
end

it 'turns the summary line red' do
expect(fully_formatted).to include('<red>3 examples, 1 failure, 1 pending</red>')
end
end

context "when there's an error outside of examples" do
let(:errors_outside_of_examples_count) do
1
end

it 'turns the summary line red' do
expect(fully_formatted).to include('<red>2 examples, 0 failures, 1 error occurred outside of examples</red>')
end
end
end
end
end