Skip to content

Rspec custom formatter to produce beautiful reports from rspec

License

Notifications You must be signed in to change notification settings

dgmora/rspec_yah_formatter

 
 

Repository files navigation

Publish pretty rspec reports with images

PLEASE NOTE - This is a fork from rspec_reports_formatter

This is a RSpec formatter which generates pretty html reports showing the results of rspec tests, where you can also easily attach images and screenshots.

Why another formatter?

On CI servers, xUnit xml test reports are quite "standard", but the attachments cannot be linked to a concrete test. I mean, just look at this.

kingsleyh created a nicer interface using an RSpec formatter with rspec_reports_formatter, but it had some issues with nested blocks and it was still not possible to attach images.

With rspec_yah_formatter you can attach images, which is very useful for capybara, selenium and so on.

Features

This report is inspired in rspec_reports_formatter, with some differences:

  • All examples are shown in the same page. This makes it simpler, and also avoids this
  • As mentioned, you can add images
  • To avoid that the page is filled with stacktraces and images, errors are by default hidden, and you can show them by clicking on them.
  • This report only makes sense in html, so you must specify a file in --outwhen running rspec

Here is also the Changelog and a TODO list

Install

This gem was build to use Rspec 3.x.x

  gem install rspec_yah_formatter -v 0.0.7

ideally just add it to your bundler Gemfile as follows:

 gem 'rspec_yah_formatter','~> 0.0.7'

Use

When running your rspec tests with rspec 3.0.0 just use the custom formatter:

This should work:

 rspec spec/my/spec -f RspecYahFormatter --out path/to/report.html

If not you can explicitly add in a require as follows:

 rspec spec/my/spec --require rspec_yah_formatter.rb --format RspecYahFormatter --out path/to/report.html

To add images:

RSpec.configure do |config|
  config.after(:each) do |example|
    if example.exception
        # Save screenshot to 'path/to/foo.png'
        example.metadata[:screenshot] = 'path/to/foo.png'
    end
  end
end

Show me something

Generated with spec/test2_spec.rb

![example report] (https://raw.githubusercontent.com/dgmora/rspec_yah_formatter/master/.README/example.png)

About

Rspec custom formatter to produce beautiful reports from rspec

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 71.9%
  • HTML 27.0%
  • CSS 1.1%