May 20, 2024

What is RSpec?

RSpec is a testing framework for Ruby.

Enabling XML Output

RSpec can be configured to produce JUnit XML output by installing the rspec_junit_formatter module.

1gem install rspec_junit_formatter

Add the formatter to your command line like this:

1rspec src --format RspecJunitFormatter

Test Suite naming

The output file can be set with the --out option like this:

1rspec src --format RspecJunitFormatter --out rspec_test.xml

By default, RSpec will include the file attribute in the output XML like this:

1<?xml version="1.0" encoding="UTF-8"?>
2<testsuite name="rspec" tests="3" skipped="0" failures="1" errors="0">
3 <testcase classname="ruby.rspec.spec.calculator_spec"
4 name="Calculator.halve given the number 3 returns 1.5"
5 file="./ruby/rspec/spec/calculator_spec.rb"
6 time="0.010126">
7 <failure message="
8expected: 1.5
9 got: 1
11(compared using ==)
12" type="RSpec::Expectations::ExpectationNotMetError">Failure/Error: expect(Calculator.halve(3)).to eq(1.5)
14 expected: 1.5
15 got: 1
17 (compared using ==)
18./ruby/rspec/spec/calculator_spec.rb:25:in `block (4 levels) in &lt;top (required)&gt;&apos;</failure>
19 </testcase>

Other Configuration

See an example of using RSpec in a GitHub action here.

Try it yourself or
request a demo

Get started for free

Try it yourself or
Request a Demo

Free for first 5 users