Module: RSpec::Core::Formatters::Helpers
- Defined in:
- lib/rspec/core/formatters/helpers.rb
Overview
Formatters helpers
Constant Summary
Class Method Summary (collapse)
-
+ (String) format_duration(duration)
private
Formats seconds into a human-readable string.
-
+ (String) format_seconds(float, precision = nil)
private
Formats seconds to have 5 digits of precision with trailing zeros removed if the number is less than 1 or with 2 digits of precision if the number is greater than zero.
-
+ (String) pluralize(count, string)
private
Pluralize a word based on a count.
Class Method Details
+ (String) format_duration(duration)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Formats seconds into a human-readable string.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/rspec/core/formatters/helpers.rb', line 22 def self.format_duration(duration) precision = case when duration < 1 then SUB_SECOND_PRECISION when duration < 120 then DEFAULT_PRECISION when duration < 300 then 1 else 0 end if duration > 60 minutes = (duration.to_i / 60).to_i seconds = duration - minutes * 60 "#{pluralize(minutes, 'minute')} #{pluralize(format_seconds(seconds, precision), 'second')}" else pluralize(format_seconds(duration, precision), 'second') end end |
+ (String) format_seconds(float, precision = nil)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Formats seconds to have 5 digits of precision with trailing zeros removed if the number is less than 1 or with 2 digits of precision if the number is greater than zero.
The precision used is set in SUB_SECOND_PRECISION and DEFAULT_PRECISION.
56 57 58 59 60 |
# File 'lib/rspec/core/formatters/helpers.rb', line 56 def self.format_seconds(float, precision=nil) precision ||= (float < 1) ? SUB_SECOND_PRECISION : DEFAULT_PRECISION formatted = "%.#{precision}f" % float strip_trailing_zeroes(formatted) end |
+ (String) pluralize(count, string)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Pluralize a word based on a count.
81 82 83 |
# File 'lib/rspec/core/formatters/helpers.rb', line 81 def self.pluralize(count, string) "#{count} #{string}#{'s' unless count.to_f == 1}" end |