Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Display both minutes and seconds of duration time when specs are finished. #563

Merged
merged 1 commit into from

3 participants

@uzzz

As far as lots of rails heavy-weight apps (mine too) runs specs much longer than tens seconds (about 23 minutes on my app for instance) because of hardcore DB seeding I think it will be useful to see "xx minutes xx seconds" in output if duration is more than 1 minute.

@justinko

I like this, it keeps me from dividing the minutes by 60 in my head :)

@dchelimsky @myronmarston any objections?

@dchelimsky
Owner

Nope.

@justinko justinko merged commit e9e31ee into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 28, 2012
  1. @uzzz
This page is out of date. Refresh to see the latest.
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
Something went wrong with that request. Please try again.