Skip to content

Commit

Permalink
Colorize summarized RSpec results.
Browse files Browse the repository at this point in the history
RSpec colorizes its results based on if there are any failures (red), pending (yellow) or none of the above (green).

The method used to summarize the results from the various threads, `summarize_results` was not doing this colorization.

This commit applies the same colorization that RSpec does but does not depend on RSpec::Core for colorization. It utilizes red for failure, yellow for pending and green for success.

- Entry in `CHANGELOG.md` added.
- Specs added for all major scenarios:
  - No failures or pending.
  - Just pending.
  - Failures and pending.
  - Just failures.

Co-authored-by: Michael Grosser <michael@grosser.it>
  • Loading branch information
joshuapinter and grosser committed Nov 22, 2020
1 parent c3faf6c commit 15d5d9a
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions spec/parallel_tests/rspec/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,42 @@ def call(*args)
end
end

describe ".summarize_results" do
subject(:colorized_results) { ParallelTests::RSpec::Runner.send(:summarize_results, [result_string]) }

context 'when there are no pending or failed tests' do
let(:result_string) { '1 example, 0 failures, 0 pendings' }

it 'is green' do
expect(colorized_results).to eq("\e[32m#{result_string}\e[0m") # 32 is green
end
end

context 'when there is a pending test and no failed tests' do
let(:result_string) { '1 example, 0 failures, 1 pending' }

it 'is yellow' do
expect(colorized_results).to eq("\e[33m#{result_string}\e[0m") # 33 is yellow
end
end

context 'when there is a pending test and a failed test' do
let(:result_string) { '1 example, 1 failure, 1 pending' }

it 'is red' do
expect(colorized_results).to eq("\e[31m#{result_string}\e[0m") # 31 is red
end
end

context 'when there is no pending tests and a failed test' do
let(:result_string) { '1 example, 1 failure, 0 pendings' }

it 'is red' do
expect(colorized_results).to eq("\e[31m#{result_string}\e[0m") # 31 is red
end
end
end

describe ".command_with_seed" do
def call(args)
base = "ruby -Ilib:test test/minitest/test_minitest_unit.rb"
Expand Down

0 comments on commit 15d5d9a

Please sign in to comment.