Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

show details for failing examples tagged with aggregate_failures: true #108

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

skaestle
Copy link

This will fix Issue #56 and was heavily inspired by #74 and all credit for the specs go to @jasoncodes

It outputs the exception.message in the case of a RSpec::Expectations::MultipleExpectationsNotMetError. This emulates what Core::Formatters::JsonFormatter does: https://github.com/rspec/rspec-core/blob/main/lib/rspec/core/formatters/json_formatter.rb#L43

Before

<?xml version="1.0" encoding="UTF-8"?>
<testsuite name="rspec" tests="1" skipped="0" failures="1" errors="0" time="0.014878" timestamp="2024-09-10T10:30:24+02:00" hostname="GREM-C02C90V3MD6V.local">
     <properties>
          <property name="seed" value="12345"/>
     </properties>
     <testcase classname="spec.example_spec" name="some example specs should support multiple failures" file="./spec/example_spec.rb" time="0.013631"><failure message="RSpec::Expectations::MultipleExpectationsNotMetError" type="RSpec::Expectations::MultipleExpectationsNotMetError">
     </failure></testcase>
</testsuite>

After

<?xml version="1.0" encoding="UTF-8"?>
<testsuite errors="0" failures="1" hostname="GREM-C02C90V3MD6V.local" name="rspec" skipped="0" tests="1" time="0.010382" timestamp="2024-09-10T10:31:22+02:00">
     <properties>
          <property name="seed" value="12345"/>
     </properties>
     <testcase classname="spec.example_spec" file="./spec/example_spec.rb" name="some example specs should support multiple failures" time="0.009463">
          <failure message="RSpec::Expectations::MultipleExpectationsNotMetError" type="RSpec::Expectations::MultipleExpectationsNotMetError">Got 2 failures from failure aggregation block:

  1) expected: 1
          got: &quot;foo&quot;

     (compared using ==)

     ./spec/example_spec.rb:53:in `block (2 levels) in &lt;top (required)&gt;'

  2) expected: 2
          got: &quot;bar&quot;

     (compared using ==)

     ./spec/example_spec.rb:54:in `block (2 levels) in &lt;top (required)&gt;'</failure>
     </testcase>
</testsuite>

@skaestle
Copy link
Author

skaestle commented Oct 7, 2024

hi there @sj26. any chance you could have a look at this PR? we have this code running on our CI (gitlab) for awhile and we have yet to see any adverse side-effects

Let me know if there is anything to help get this PR into the main

@sj26
Copy link
Owner

sj26 commented Feb 9, 2025

This looks like a good solution.

The only potential problem is compatibility. Does this work for all rspec versions currently supported by the gem?

@sj26
Copy link
Owner

sj26 commented Feb 9, 2025

This doesn't seem to work for rspec 3.0 for example:

/Users/sj26/Developer/rspec_junit_formatter/lib/rspec_junit_formatter/rspec3.rb:92:in `failure_for': uninitialized constant RSpec::Expectations::MultipleExpectationsNotMetError (NameError)

    if exception.is_a?(RSpec::Expectations::MultipleExpectationsNotMetError)
                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        from /Users/sj26/Developer/rspec_junit_formatter/lib/rspec_junit_formatter.rb:63:in `block in xml_dump_failed'

@skaestle
Copy link
Author

skaestle commented Feb 11, 2025

Thanks for getting back to me. And sorry for not checking bundle exec rake.

It appears that aggregate_failures was introduced with rspec 3.3. I fixed the issue. Let me know what you think, thanks!

(Now I see @jasoncodes had already correctly handled that in the specs.)

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants