Module: RSpec::Core::Formatters::Helpers

Included in:
BaseFormatter
Defined in:
lib/rspec/core/formatters/helpers.rb

Constant Summary collapse

SUB_SECOND_PRECISION =
5
DEFAULT_PRECISION =
2

Instance Method Summary collapse

Instance Method Details

#format_seconds(float) ⇒ Object



11
12
13
14
15
# File 'lib/rspec/core/formatters/helpers.rb', line 11

def format_seconds(float)
  precision ||= (float < 1) ? SUB_SECOND_PRECISION : DEFAULT_PRECISION
  formatted = sprintf("%.#{precision}f", float)
  strip_trailing_zeroes(formatted)
end

#strip_trailing_zeroes(string) ⇒ Object



17
18
19
20
# File 'lib/rspec/core/formatters/helpers.rb', line 17

def strip_trailing_zeroes(string)
  stripped = string.sub(/[^1-9]+$/, '')
  stripped.empty? ? "0" : stripped
end