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

Commit 2bda6b7

Browse files
authored
Merge pull request #2779 from cntral/pluralize_words_ending_in_s
Allow `pluralize` to handle words that end with s.
2 parents eb06502 + e3e003e commit 2bda6b7

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

lib/rspec/core/formatters/helpers.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,15 @@ def self.strip_trailing_zeroes(string)
8686
# @param string [String] word to be pluralized
8787
# @return [String] pluralized word
8888
def self.pluralize(count, string)
89-
"#{count} #{string}#{'s' unless count.to_f == 1}"
89+
pluralized_string = if count.to_f == 1
90+
string
91+
elsif string.end_with?('s') # e.g. "process"
92+
"#{string}es" # e.g. "processes"
93+
else
94+
"#{string}s"
95+
end
96+
97+
"#{count} #{pluralized_string}"
9098
end
9199

92100
# @api private

spec/rspec/core/formatters/helpers_spec.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,5 +117,38 @@
117117
end
118118
end
119119

120+
describe "pluralize" do
121+
context "when word does not end in s" do
122+
let(:word){ "second" }
123+
124+
it "pluralizes with 0" do
125+
expect(helper.pluralize(0, "second")).to eq("0 seconds")
126+
end
127+
128+
it "does not pluralizes with 1" do
129+
expect(helper.pluralize(1, "second")).to eq("1 second")
130+
end
131+
132+
it "pluralizes with 2" do
133+
expect(helper.pluralize(2, "second")).to eq("2 seconds")
134+
end
135+
end
136+
137+
context "when word ends in s" do
138+
let(:word){ "process" }
139+
140+
it "pluralizes with 0" do
141+
expect(helper.pluralize(0, "process")).to eq("0 processes")
142+
end
143+
144+
it "does not pluralizes with 1" do
145+
expect(helper.pluralize(1, "process")).to eq("1 process")
146+
end
147+
148+
it "pluralizes with 2" do
149+
expect(helper.pluralize(2, "process")).to eq("2 processes")
150+
end
151+
end
152+
end
120153

121154
end

0 commit comments

Comments
 (0)