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.59 got: 11011(compared using ==)12" type="RSpec::Expectations::ExpectationNotMetError">Failure/Error: expect(Calculator.halve(3)).to eq(1.5)1314 expected: 1.515 got: 11617 (compared using ==)18./ruby/rspec/spec/calculator_spec.rb:25:in `block (4 levels) in <top (required)>'</failure>19 </testcase>20</testsuite>21
Other Configuration
See an example of using RSpec in a GitHub action here.