Repository navigation
feat(rspec): report shared and library-defined examples at their spec location - #1365
Open
TylerJang27 wants to merge 3 commits into
Open
TylerJang27 wants to merge 3 commits into
TylerJang27 wants to merge 3 commits into
Conversation
… location With TRUNK_REPORT_SPEC_LOCATION=true, an example defined outside its spec file (a shared example, or rswag's run_test!) is reported at the spec file RSpec reruns it from: the it_behaves_like or include_examples line, or else the nearest enclosing group in the spec. Code owners follow that file. It is opt-in because the file is part of a test's id. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Merging to
After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here |
The location spec now defines its rswag example with rswag-specs 2.17.0 instead of a stand-in. The lockfile is resolved under Ruby 3.1, which the unit-test job runs, so it takes Rails 7.2 components. The upload harness Gemfile gets rswag-specs too, since the main-branch smoke run executes the same suite there. A shared-group inclusion frame with no location no longer raises. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1365 +/- ##
==========================================
+ Coverage 85.62% 85.84% +0.21%
==========================================
Files 85 85
Lines 19192 19204 +12
==========================================
+ Hits 16434 16485 +51
+ Misses 2758 2719 -39 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
rswag-specs brings in nokogiri, which ships native builds for many platforms, and Bundler puts every one of them in the harness lockfile. The built gem exists for one platform only, so `bundle install --local` could not resolve it. The harness now locks to the gem's own platform before adding it to the Gemfile. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A customer asked for this. The gem reports each example at
metadata[:file_path]andmetadata[:line_number], which is where the example block is written:run_test!, it's the rswag gem's ownexample_group_helpers.rb. That path is outside the repo, so no CODEOWNERS rule matches it.Code owners are resolved in the gem from that file. So these tests get the owners of the shared file, or no owners at all.
Change
A new opt-in,
TRUNK_REPORT_SPEC_LOCATION=true, changes how an example defined outside its spec file is reported. That's any example wherefile_pathdiffers fromrerun_file_path:rerun_file_path, the spec file RSpec reruns the example from. The dotted classname is derived from it as before.it_behaves_likeorinclude_examples, the line of that call, read from the outermostshared_group_inclusion_backtraceframe in that file.responseblock aroundrun_test!, because RSpec doesn't record whererun_test!was called.The quarantine lookup uses the same file and classname as the upload, so the two stay consistent.
An example defined in its own spec file is reported exactly as before, whether or not the variable is set.
What this means for other customers
The change is opt-in, so nothing changes for anyone who doesn't set the variable. For anyone who does, or if it ever becomes the default:
it { is_expected.to ... }) keep their ids, because their id is built fromtrunk:<id>-<location>and doesn't include the file.include_examplesin the same context, used to have separate ids because their files differed. They now share one id.responsegroup, not therun_test!line.UPGRADING.md.Moving quarantines to the new ids. After the first upload with the variable set, we match old and new test cases on parent and name within the same collection, repo, and variant, and copy quarantines with
POST /v2/tests/quarantine:To avoid failures before the copy, make the first upload from a branch that doesn't gate merges.
Testing
test/location_spec.rb, run in a sandbox. Shared examples are defined in a support file. Therun_test!example comes from the real rswag-specs gem (MIT), usingpath,getandresponse. It covers:it_behaves_likeinclude_examplesin a nested contextrun_test!bundle exec rspec test/: 67 examples, 0 failures (Ruby 3.3, rspec-core 3.13.2, native extension built locally).trunk checkcouldn't run here because trunk didn't find the system Rust runtime.rswag-specs is a test-only dependency, and it's heavy.
Gemfile, not the gemspec, so nothing changes for gem users.rake testjob runs Ruby 3.1. Under Ruby 3.3 it resolves to Rails 8.1, which needs Ruby 3.2 or newer.Gemfilealso adds it, unpinned and with no lockfile. The main-branch smoke run executes this suite there on Ruby 3.1 to 4.0, so each Ruby resolves its own version. Every run of the harness now installs those gems.🤖 Generated with Claude Code