Skip to content

Commit

Permalink
Pluralize 'spec(s) per process' (#792)
Browse files Browse the repository at this point in the history
  • Loading branch information
brchristian committed Dec 4, 2020
1 parent 117cce9 commit 54cc798
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
12 changes: 11 additions & 1 deletion lib/parallel_tests/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,17 @@ def report_number_of_tests(groups)
num_processes = groups.size
num_tests = groups.map(&:size).inject(0, :+)
tests_per_process = (num_processes == 0 ? 0 : num_tests / num_processes)
puts "#{num_processes} processes for #{num_tests} #{name}s, ~ #{tests_per_process} #{name}s per process"
puts "#{pluralize(num_processes, 'process')} for #{pluralize(num_tests, name)}, ~ #{pluralize(tests_per_process, name)} per process"
end

def pluralize(n, singular)
if n == 1
"1 #{singular}"
elsif singular.end_with?('s', 'sh', 'ch', 'x', 'z')
"#{n} #{singular}es"
else
"#{n} #{singular}s"
end
end

#exit with correct status code so rake parallel:test && echo 123 works
Expand Down
10 changes: 5 additions & 5 deletions spec/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def self.it_fails_without_any_files(type)
end
end

let(:printed_commands) { "specs per process\nbundle exec rspec" }
let(:printed_commands) { /specs? per process\nbundle exec rspec/ }
let(:printed_rerun) { "run the group again:\n\nbundle exec rspec" }

it "runs tests in parallel" do
Expand All @@ -80,7 +80,7 @@ def self.it_fails_without_any_files(type)
expect(result).to include_exactly_times(/Took \d+ seconds/, 1) # parallel summary

# verify empty groups are discarded. if retained then it'd say 4 processes for 2 specs
expect(result).to include '2 processes for 2 specs, ~ 1 specs per process'
expect(result).to include '2 processes for 2 specs, ~ 1 spec per process'
end

describe "--fail-fast" do
Expand Down Expand Up @@ -168,7 +168,7 @@ def test_unicode
write 'spec/xxx_spec.rb', 'describe("it"){it("should"){puts "TEST1"}}'
write 'spec/xxx2_spec.rb', 'describe("it"){it("should"){expect(1).to eq(2)}}'
result = run_tests "spec --verbose", type: 'rspec', fail: true
expect(result).to include printed_commands
expect(result).to match printed_commands
expect(result).to include printed_rerun
expect(result).to include "bundle exec rspec spec/xxx_spec.rb"
expect(result).to include "bundle exec rspec spec/xxx2_spec.rb"
Expand All @@ -178,14 +178,14 @@ def test_unicode
write 'spec/xxx_spec.rb', 'describe("it"){it("should"){expect(1).to eq(2)}}'
result = run_tests "spec --verbose-rerun-command", type: 'rspec', fail: true
expect(result).to include printed_rerun
expect(result).to_not include printed_commands
expect(result).to_not match printed_commands
end

it "shows only process with --verbose-process-command" do
write 'spec/xxx_spec.rb', 'describe("it"){it("should"){expect(1).to eq(2)}}'
result = run_tests "spec --verbose-process-command", type: 'rspec', fail: true
expect(result).to_not include printed_rerun
expect(result).to include printed_commands
expect(result).to match printed_commands
end

it "fails when tests fail" do
Expand Down

0 comments on commit 54cc798

Please sign in to comment.