Closed maschwenk closed 6 years ago
Unfortunately, the junit xml standard does not include a line number in the file attribute, and this will break current consumers of the xml output. We also considered adding a new attribute in #38, but it broke other consumers of the xml output which rely on xsd validation.
The best we can offer here is relying on the stack trace. Rspec should be adding a stack trace to the failure messsage, including the file and line number for re-running:
<testcase classname="spec.example_spec" name="some example specs shows diffs cleanly" file="./spec/example_spec.rb" time="0.001777"><failure message="
expected: {:a=>2, :c=>4}
got: {:a=>"b", :c=>"d"}
(compared using eql?)
Diff:
@@ -1,3 +1,3 @@
-:a => 2,
-:c => 4,
+:a => "b",
+:c => "d",
" type="RSpec::Expectations::ExpectationNotMetError">Failure/Error: expect({a: "b", c: "d"}).to eql({a: 2, c: 4})
expected: {:a=>2, :c=>4}
got: {:a=>"b", :c=>"d"}
(compared using eql?)
Diff:
@@ -1,3 +1,3 @@
-:a => 2,
-:c => 4,
+:a => "b",
+:c => "d",
./spec/example_spec.rb:26:in `block (2 levels) in <top (required)>'
./spec/spec_helper.rb:7:in `block (2 levels) in <top (required)>'</failure></testcase>
Do you have specs which aren't producing a stack trace? Can you provide an example?
On review, I'm not even sure that the file attribute is included in the xsd either. Maybe we should just add another attribute? Idk.
The canonical junit implementation is here:
Note that if you just want machine-readable output, you can use rspec's built-in json output:
https://github.com/rspec/rspec-core/blob/master/lib/rspec/core/formatters/json_formatter.rb
If you specifically want something to be consumed by a junit parser, we need something that's valid output, hence my caution.
@sj26 Understood, I just wanted to avoid regex parsing a stacktrace but maybe that's not so bad if the format is standard
Shows the line number in the file path
This is really helpful because it means I can literally take the failed example and paste directly into my CLI to run the test, rather than hunting down for the actual example that failed within the file