Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #681 from twe4ked/pluralize-seconds

Pluralize 'second' in RSpec::Core::Formatters::Helpers#format_duration
  • Loading branch information...
commit 1a57965c2734f4b869484a9c24e8447dd8b040c5 2 parents ffb48f5 + efeb497
@dchelimsky dchelimsky authored
View
6 lib/rspec/core/formatters/helpers.rb
@@ -11,9 +11,9 @@ def format_duration(duration)
minutes = duration.to_i / 60
seconds = duration - minutes * 60
- "#{pluralize(minutes, 'minute')} #{format_seconds(seconds)} seconds"
+ "#{pluralize(minutes, 'minute')} #{pluralize(format_seconds(seconds), 'second')}"
else
- "#{format_seconds(duration)} seconds"
+ pluralize(format_seconds(duration), 'second')
end
end
@@ -29,7 +29,7 @@ def strip_trailing_zeroes(string)
end
def pluralize(count, string)
- "#{count} #{string}#{'s' unless count == 1}"
+ "#{count} #{string}#{'s' unless count.to_f == 1}"
end
end
View
12 spec/rspec/core/formatters/helpers_spec.rb
@@ -22,6 +22,18 @@
helper.format_duration(45.5).should eq("45.5 seconds")
end
end
+
+ context '= 61' do
+ it "returns 'x minute x second' formatted string" do
+ helper.format_duration(61).should eq("1 minute 1 second")
+ end
+ end
+
+ context '= 1' do
+ it "returns 'x second' formatted string" do
+ helper.format_duration(1).should eq("1 second")
+ end
+ end
end
describe "format seconds" do
Please sign in to comment.
Something went wrong with that request. Please try again.