fix(rspec): report correct status for pending/skipped examples#1136
Conversation
|
😎 Merged directly without going through the merge queue, as the queue was empty and the PR was up to date with the target branch - details. |
298c6db to
cb1482a
Compare
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1136 +/- ##
==========================================
+ Coverage 82.51% 82.77% +0.26%
==========================================
Files 70 70
Lines 15588 15588
==========================================
+ Hits 12862 12903 +41
+ Misses 2726 2685 -41 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
RSpec expresses a `pending` example's outcome as the inverse of its body:
a pending example whose body still fails is reported as :pending (build
stays green — the "should fail" expectation was met), while one whose body
now passes is reported as :failed via PendingExampleFixedError (build goes
red).
Split the status decision into TrunkAnalyticsListener#status_and_exception,
which reports the outcome RSpec actually decided (which also matches the
build result):
- skip / xit (never ran) -> skipped (detected explicitly via
metadata[:skip], since RSpec reports
skips as :pending too)
- pending, body still failing -> success (expectation met)
- pending, body now passing -> failure (PendingExampleFixedError)
RSpec's own build pass/fail behavior is left untouched. Adds a test in the
gem suite that runs real pending/skip examples in an RSpec sandbox and
asserts the mapping.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
cb1482a to
e8b0c34
Compare
TylerJang27
left a comment
There was a problem hiding this comment.
One blocker on the smoke tests
| started_at, finished_at, failure_message || '', backtrace || '', is_quarantined) | ||
| end | ||
|
|
||
| # Determine the Trunk status to report for an example, plus the exception (if |
There was a problem hiding this comment.
Note that this could be a breaking change for users of TRUNK_LOCAL_UPLOAD_DIR, but I agree with your choices here
| # Includes a pending example whose body unexpectedly passed: RSpec reports it | ||
| # as :failed with a PendingExampleFixedError (on example.exception) and breaks |
There was a problem hiding this comment.
Sanity check: this should rspec exit code 0, but we would see that is as nonzero nonquarantined failures.
Let's make sure this runs for a few cycles of smoke tests
You'll need to enumerate this file in .github/actions/test_ruby_gem_uploads/action.yaml, probs in run-regular-tests
There was a problem hiding this comment.
I've configured the smoke test action to optionally run the unit tests with the compiled gem. The ruby.yaml won't run the unit tests, but the smoke_test.yaml and smoke_test_main.yaml will.
3d8fa1e to
46165da
Compare
Exercise the gem's portable unit suite (rspec-trunk-flaky-tests/test) against the built, packaged gem in the periodic main-branch smoke workflow, without duplicating it on every PR. - test/ specs now `require 'rspec_trunk_flaky_tests'` (resolves to source under `rake test`, or the installed built gem in smoke) instead of require_relative-ing the source lib; Rakefile test task gains -Ilib. - The test_ruby_gem_uploads action gains a `run-gem-unit-suite` input (default false) that runs `rspec $GITHUB_WORKSPACE/rspec-trunk-flaky-tests/test` against the built gem with auto-upload disabled. - smoke_test_main.yml enables it (its checkout matches the built gem). PR callers (ruby.yml) leave it off, so `rake test` remains the sole PR run of these specs. smoke_test.yml (released gem) is intentionally left off to avoid source/release version skew. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
46165da to
4cf6afa
Compare
Problem
The RSpec plugin didn't handle
pendingexamples correctly, because RSpec expresses a pending example's outcome as the inverse of its body:status:pendingPendingExampleFixedError):failedReporting the raw status meant a still-broken pending test was recorded as skipped — never counted as failing, so it could never be quarantined — while a fixed one was recorded as a failure. Genuine
skip/xit(which RSpec also reports as:pending) couldn't be told apart from a failing pending test.Fix
Split the status decision into
TrunkAnalyticsListener#status_and_exception, which reports the outcome RSpec actually decided (which also matches the build result):skip/xit(never ran) → skipped — detected explicitly viametadata[:skip], up front, since RSpec reports skips as:pendingtoopending, body still failing → success (the "should fail" expectation was met)pending, body now passing → failure (PendingExampleFixedError; error pulled fromexample.exception)RSpec's own build pass/fail behavior is left untouched (
#set_exception) — a fixed pending example still fails the run; we only change what status/error is reported to Trunk.Tests
Adds
test/pending_status_spec.rbto the gem suite. It runs real pending/skip examples inside anRSpec::Core::Sandbox(so the fixed-pending's failure doesn't fail this suite) and asserts the mapping against genuine RSpec behavior.Verification
Built the native extension and ran the full gem suite locally: 18 examples, 0 failures (13 existing + 5 new). Also confirmed end-to-end that the reported statuses serialize as
skipped / success / failureas expected.🤖 Generated with Claude Code