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



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

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



15
16
17
18
# File 'lib/rspec/core/formatters/helpers.rb', line 15

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