Skip to content


This is a proposal to add example duration to the the html formatter's output #451

merged 1 commit into from

2 participants


This is just a conversation starter. Happy to modify the actual implementation as you see fit. In particular, I haven't updated the html formatter spec yet, since I want to get feedback on this implementation before jumping through all the specs.


Couple of thoughts: this should be implemented in as a method in the base formatter that subclasses can use. Also, probably better to measure in milliseconds. WDYT?


Actually, the measurement already exists as metadata on each example: example.execution_result[:run_time], so we don't need to measure it. That can get wrapped in a method in the formatter, but best if that method uses what's already there.

See for an example of how we're already using it.


Updated the diff:

Thanks for the pointer on run time. Glad to not have to reinvent the wheel.
I made the output go down to ms: sprintf("%.3f", example.execution_result[:run_time])

I think it makes sense to not give the full precision on it, since it's probably not meaningful to multiple decimal places, especially when compared to the space it'd take up. To ms doesn't seem to bad though. Your thoughts?

Updated image

Also could see truncating Finished in to 3 decimal places.

@dchelimsky dchelimsky merged commit 001522b into rspec:master
@dchelimsky dchelimsky referenced this pull request from a commit
@dchelimsky dchelimsky Use 5 decimal places for time reports in html formatter.
- also update formatter specs and gold masters
- #451

@richievos - 3 decimal places resulted in a bunch of examples with 0.000s. On the one hand it made me happy that they took virtually no time, but it was also not very helpful :)

I played around w/ different numbers and landed on 5, and updated the total run time and the time for failed examples to use the same format.

@dchelimsky dchelimsky referenced this pull request from a commit
@dchelimsky dchelimsky changelog for #451 8de2a97

I was debating the number of decimal places to go with. I chose 3 because it seemed like anything below milliseconds was probably going to be noise, or something I personally wouldn't be that interested in. Meaning, that the 4th and 5th decimal place were probably below the level where they'd be realistically something I'd bother looking into, and may be noisy enough that they're not reliably useful.

However, your specs hopefully run faster than mine, so your call :)

Thanks for the merge!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 30, 2011
  1. @richievos
This page is out of date. Refresh to see the latest.
Showing with 8 additions and 1 deletion.
  1. +8 −1 lib/rspec/core/formatters/html_formatter.rb
9 lib/rspec/core/formatters/html_formatter.rb
@@ -67,7 +67,7 @@ def example_started(example)
def example_passed(example)
- @output.puts " <dd class=\"example passed\"><span class=\"passed_spec_name\">#{h(example.description)}</span></dd>"
+ @output.puts " <dd class=\"example passed\"><span class=\"passed_spec_name\">#{h(example.description)}</span><span class='duration'>#{sprintf("%.3f", example.execution_result[:run_time])}s</span></dd>"
@@ -84,6 +84,7 @@ def example_failed(example)
@output.puts " <dd class=\"example #{failure_style}\">"
@output.puts " <span class=\"failed_spec_name\">#{h(example.description)}</span>"
+ @output.puts " <span class=\"duration\">#{sprintf('%.1f', example.execution_result[:run_time])}s</span>"
@output.puts " <div class=\"failure\" id=\"failure_#{@failed_examples.size}\">"
@output.puts " <div class=\"message\"><pre>#{h(exception.message)}</pre></div>" unless exception.nil?
@output.puts " <div class=\"backtrace\"><pre>#{format_backtrace(exception.backtrace, example).join("\n")}</pre></div>" if exception
@@ -352,6 +353,12 @@ def global_styles
padding: 3px 3px 3px 18px;
+dd .duration {
+ padding-left: 5px;
+ text-align: right;
+ right: 0px;
+ float:right;
dd.example.passed {
border-left: 5px solid #65C400;
Something went wrong with that request. Please try again.