Last active
February 12, 2018 12:42
-
-
Save tylerhunt/fd60ff3a06eb6c65624cb4c9bfdcd306 to your computer and use it in GitHub Desktop.
Visualize the state of an RSpec suite using the cached example status.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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, whilevisualize_specs.rb
is effectively the same code in a more readable form.Legend
Notes
Hovering over a tile will give you the spec file and line number.
Example Output