Skip to content
This repository

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

merged 1 commit into from over 2 years ago

2 participants

Richie Vos David Chelimsky
Richie Vos

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.

David Chelimsky

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?

David Chelimsky

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.

Richie Vos

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.

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

@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.

David Chelimsky dchelimsky referenced this pull request from a commit
David Chelimsky dchelimsky changelog for #451 8de2a97
Richie Vos

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

Showing 1 unique commit by 1 author.

Aug 30, 2011
Richie Vos richievos Add example duration to html formatter 41f6956
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 8 additions and 1 deletion. Show diff stats Hide diff stats

  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)
67 67
68 68 def example_passed(example)
69 69 move_progress
70   - @output.puts " <dd class=\"example passed\"><span class=\"passed_spec_name\">#{h(example.description)}</span></dd>"
  70 + @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>"
71 71 @output.flush
72 72 end
73 73
@@ -84,6 +84,7 @@ def example_failed(example)
84 84 move_progress
85 85 @output.puts " <dd class=\"example #{failure_style}\">"
86 86 @output.puts " <span class=\"failed_spec_name\">#{h(example.description)}</span>"
  87 + @output.puts " <span class=\"duration\">#{sprintf('%.1f', example.execution_result[:run_time])}s</span>"
87 88 @output.puts " <div class=\"failure\" id=\"failure_#{@failed_examples.size}\">"
88 89 @output.puts " <div class=\"message\"><pre>#{h(exception.message)}</pre></div>" unless exception.nil?
89 90 @output.puts " <div class=\"backtrace\"><pre>#{format_backtrace(exception.backtrace, example).join("\n")}</pre></div>" if exception
@@ -352,6 +353,12 @@ def global_styles
352 353 padding: 3px 3px 3px 18px;
353 354 }
354 355
  356 +dd .duration {
  357 + padding-left: 5px;
  358 + text-align: right;
  359 + right: 0px;
  360 + float:right;
  361 +}
355 362
356 363 dd.example.passed {
357 364 border-left: 5px solid #65C400;

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.