Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

base text formatter now displays "xx minute(s) xx seconds" if more th…

…an 60 seconds
  • Loading branch information...
commit 76be2a821876db5b766fd276d2cb9f92174903a1 1 parent 8e8fb2b
Maksim Zhylinski uzzz authored
2  lib/rspec/core/formatters/base_text_formatter.rb
View
@@ -35,7 +35,7 @@ def dump_summary(duration, example_count, failure_count, pending_count)
super(duration, example_count, failure_count, pending_count)
# Don't print out profiled info if there are failures, it just clutters the output
dump_profile if profile_examples? && failure_count == 0
- output.puts "\nFinished in #{format_seconds(duration)} seconds\n"
+ output.puts "\nFinished in #{format_duration(duration)}\n"
output.puts colorise_summary(summary_line(example_count, failure_count, pending_count))
dump_commands_to_rerun_failed_examples
end
11 lib/rspec/core/formatters/helpers.rb
View
@@ -6,6 +6,17 @@ module Helpers
SUB_SECOND_PRECISION = 5
DEFAULT_PRECISION = 2
+ def format_duration(duration)
+ if duration > 60
+ minutes = duration.to_i / 60
+ seconds = duration - minutes * 60
+
+ "#{minutes} minute(s) #{format_seconds(seconds)} seconds"
+ else
+ "#{format_seconds(duration)} seconds"
+ end
+ end
+
def format_seconds(float)
precision ||= (float < 1) ? SUB_SECOND_PRECISION : DEFAULT_PRECISION
formatted = sprintf("%.#{precision}f", float)
14 spec/rspec/core/formatters/helpers_spec.rb
View
@@ -4,6 +4,20 @@
describe RSpec::Core::Formatters::Helpers do
let(:helper) { Object.new.extend(RSpec::Core::Formatters::Helpers) }
+ describe "format duration" do
+ context '> 60' do
+ it "returns 'x minute(s) xx seconds' formatted string" do
+ helper.format_duration(135.14).should eq("2 minute(s) 15.14 seconds")
+ end
+ end
+
+ context '< 60' do
+ it "returns 'xx seconds' formatted string" do
+ helper.format_duration(45.5).should eq("45.5 seconds")
+ end
+ end
+ end
+
describe "format seconds" do
context "sub second times" do
it "returns 5 digits of precision" do
Please sign in to comment.
Something went wrong with that request. Please try again.