Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #563 from uzzz/master

Display both minutes and seconds of duration time when specs are finished.
  • Loading branch information...
commit e9e31ee26ff414123871a113d26860d870347710 2 parents 8e8fb2b + 76be2a8
@justinko justinko authored
View
2  lib/rspec/core/formatters/base_text_formatter.rb
@@ -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
View
11 lib/rspec/core/formatters/helpers.rb
@@ -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)
View
14 spec/rspec/core/formatters/helpers_spec.rb
@@ -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.