Skip to content

Instantly share code, notes, and snippets.

@tylerhunt
Last active February 12, 2018 12:42
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tylerhunt/fd60ff3a06eb6c65624cb4c9bfdcd306 to your computer and use it in GitHub Desktop.
Save tylerhunt/fd60ff3a06eb6c65624cb4c9bfdcd306 to your computer and use it in GitHub Desktop.
Visualize the state of an RSpec suite using the cached example status.
require 'rspec/core'
css = %(
<style>
html { font-size: 50%; }
.unknown, .passed, .pending, .failed { display: inline-block; height: 1rem; width: 1rem; }
.unknown { background-color: #999; }
.pending { background-color: #FC0; }
.passed { background-color: #3F3; }
.failed { background-color: #F33; }
</style>
)
html = RSpec::Core::ExampleStatusPersister
.load_from('spec/examples.txt')
.collect { |row| %(<div class="#{row[:status]}" title="#{row[:example_id]}"></div>) }
.join("\n")
File.write 'spec/examples.html', [css, html].join
ruby -r rspec/core -e 'File.write "spec/examples.html", %(<style>html { font-size: 50%; } .unknown, .passed, .pending, .failed { display: inline-block; height: 1rem; width: 1rem; } .unknown { background-color: #999; } .pending { background-color: #FC0; } .passed { background-color: #3F3; } .failed { background-color: #F33; }</style>) + RSpec::Core::ExampleStatusPersister.load_from("spec/examples.txt").collect { |row| %(<div class="#{row[:status]}" title="#{row[:example_id]}"></div>) }.join("\n")'
@tylerhunt
Copy link
Author

tylerhunt commented Feb 9, 2018

Visualize Specs

RSpec generates a cache of example statuses on each run (typically stored in spec/examples.txt). This script uses RSpec's parser to load this data and turn it into a simple HTML page that makes it easy to see the state of your spec suite at a glance.

The file visualize_specs.sh is a one-liner that can be copied-and-pasted onto the command line, while visualize_specs.rb is effectively the same code in a more readable form.

Legend

  • green — passing
  • red — failing
  • yellow — pending
  • gray — unknown

Notes

Hovering over a tile will give you the spec file and line number.

Example Output

screen shot 2018-02-09 at 15 03 34

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment