No release in over 3 years
Low commit activity in last 3 years
RSpec Junit Formatter results that your CI can read in Bitbucket Pipeline. Use convention http://reflex.gforge.inria.fr
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.2
~> 1.17, >= 1.17.3
~> 1.1, >= 1.1.2
~> 1.8, >= 1.8.2
~> 0.12.2
~> 12.3, >= 12.3.2

Runtime

>= 2, != 2.12.0, < 4
 Project Readme

RSpec JUnit Formatter

Build results Gem version

RSpec 2 & 3 results that your CI can read. Jenkins, Buildkite, CircleCI, and probably more, too.

Usage

Install the gem:

gem install rspec_junit_formatter

Use it:

rspec --format RspecJunitFormatter --out rspec.xml

You'll get an XML file rspec.xml with your results in it.

You can use it in combination with other formatters, too:

rspec --format progress --format RspecJunitFormatter --out rspec.xml

Using in your project with Bundler

Add it to your Gemfile if you're using Bundler. Put it in the same groups as rspec.

group :test do
  gem "rspec"
  gem "rspec_junit_formatter"
end

Put the same arguments as the commands above in your .rspec:

--format RspecJunitFormatter
--out rspec.xml

Parallel tests

For use with parallel_tests, add $TEST_ENV_NUMBER in the output file option (in .rspec or .rspec_parallel) to avoid concurrent process write conflicts.

--format RspecJunitFormatter
--out tmp/rspec<%= ENV["TEST_ENV_NUMBER"] %>.xml

The formatter includes $TEST_ENV_NUMBER in the test suite name within the XML, too.

Capturing output

If you like, you can capture the standard output and error streams of each test into the :stdout and :stderr example metadata which will be added to the junit report, e.g.:

# spec_helper.rb

RSpec.configure do |config|
  # register around filter that captures stdout and stderr
  config.around(:each) do |example|
    $stdout = StringIO.new
    $stderr = StringIO.new

    example.run

    example.metadata[:stdout] = $stdout.string
    example.metadata[:stderr] = $stderr.string

    $stdout = STDOUT
    $stderr = STDERR
  end
end

Caveats

  • XML can only represent a limited subset of characters which excludes null bytes and most control characters. This gem will use character entities where possible and fall back to replacing invalid characters with Ruby-like escape codes otherwise. For example, the null byte becomes \0.

Roadmap

  • It would be nice to split things up into individual test suites, although would this correspond to example groups? The subject? The spec file? Not sure yet.

Development

Run the specs with bundle exec rake, which uses Appraisal to run the specs against all supported versions of rspec.

Releasing

Bump the gem version in the gemspec, and commit. Then bundle exec rake build to build a gem package, bundle exec rake install to install and test it locally, then bundle exec rake release to tag and push the commits and gem.

License

The MIT License, see LICENSE.

Thanks

Inspired by the work of Diego Souza on RSpec Formatters after frustration with CI Reporter.