Open
Conversation
d0be728 to
302077e
Compare
Contributor
|
✅ Cop-check results (8 shards)
All shards passed — ready to merge. |
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.
Automated fix fix for
RSpec/SubjectStubcorpus conformance.Refs #588
Details
RSpec/SubjectStubResult
Changes
Agent conversation excerpt
Reading the CI instructions and the cop’s current implementation first, then I’ll verify RuboCop on the representative FP pattern before deciding whether this is a detection bug or a config/context issue.
Reading the CI instructions and the cop’s current implementation first, then I’ll verify RuboCop on the representative FP pattern before deciding whether this is a detection bug or a config/context issue.
The current fixture already has the five FN snippets appended at top level, which is suspicious. I’m checking the rest of the cop implementation and then I’ll run RuboCop on the representative FP case plus the broader pattern the prompt called out.
The current fixture already has the five FN snippets appended at top level, which is suspicious. I’m checking the rest of the cop implementation and then I’ll run RuboCop on the representative FP case plus the broader pattern the prompt called out.
let(:upgrader) { instance_double(DockerManager::Upgrader, `
before do
allow(foo).to receive(:bar).and_return(baz)
end
end
RUBY
rubocop --only RSpec/SubjectStu`
The system
rubocopdoesn’t haverubocop-rspecloaded, so the direct command from the prompt isn’t enough in this environment. I’m checking how this repo expects RuboCop to be invoked so I can verify against the actualRSpec/SubjectStubcop instead of a missing plugin.The system
rubocopdoesn’t haverubocop-rspecloaded, so the direct command from the prompt isn’t enough in this environment. I’m checking how this repo expects RuboCop to be invoked so I can verify against the actualRSpec/SubjectStubcop instead of a missing plugin.tests/fixtures/cops/rspec/subject_stub/offense.rbis already dirty before I’ve edited anything. I’m checking that diff now so I can avoid clobbering unrelated work and decide whether those appended FN snippets are part of the task setup or an incomplete prior attempt.tests/fixtures/cops/rspec/subject_stub/offense.rbis already dirty before I’ve edited anything. I’m checking that diff now so I can avoid clobbering unrelated work and decide whether those appended FN snippets are part of the task setup or an incomplete prior attempt.I’ve got the local RuboCop extension checkout. Next I’m using the vendored
rubocop-rspecbundle so theRSpec/SubjectStubcop is actually loaded, then I’ll inspect the current fixture failure state before touching code.I’ve got the local RuboCop extension checkout. Next I’m using the vendored
rubocop-rspecbundle so theRSpec/SubjectStubcop is actually loaded, then I’ll inspect the current fixture failure state before touching code.The local problem is clearer now: all 17 FP examples in the prompt are either config-dependent or oracle artifacts, while the only concrete failing signal in this checkout is the malformed FN fixture. I’m verifying whether I can load the vendored
rubocop-rspecdirectly without a full bundle install, and then I’ll replace the broken top-level snippets with a real nested example that reproduces the miss.The local problem is clearer now: all 17 FP examples in the prompt are either config-dependent or oracle artifacts, while the only concrete failing signal in this checkout is the malformed FN fixture. I’m verifying whether I can load the vendored
rubocop-rspecdirectly without a full bundle install, and then I’ll replace the broken top-level snippets with a real nested example that reproduces the miss.let(:upgrader) { instance_double(DockerManage`
before do
allow(foo).to receive(:bar).and_return(baz)
end
end
RUBY
rubocop --require `
let(:upg`
before do
allow(foo).to receive(:bar).and_return(b`
I found why the quick RuboCop run was crashing: loading the local extension without its default config leaves
config['RSpec']['Language']nil. I’m rerunning with the vendoredrubocop-rspecdefault config inherited so the comparison is meaningful.I found why the quick RuboCop run was crashing: loading the local extension without its default config leaves
config['RSpec']['Language']nil. I’m rerunning with the vendoredrubocop-rspecdefault config inherited so the comparison is meaningful.let(:upg`
before do
allow(foo).to receive(:bar).and_return(b`
The previous RuboCop run looked clean for both cases because I used
/tmp/*.rb, so the cop never actually applied under RSpec’sIncludeglobs. I’m rerunning both snippets under spec-like paths now, plus I’m checking the vendored default config for this cop’s file globs.The previous RuboCop run looked clean for both cases because I used
/tmp/*.rb, so the cop never actually applied under RSpec’sIncludeglobs. I’m rerunning both snippets under spec-like paths now, plus I’m checking the vendored default config for this cop’s file globs.before do
allow(foo).to receive(:bar)`
I’ve isolated the detection bug. The cop stops after reporting the outer
expect(subject).to receive(:fork) do ... end, so it never descends into that block and misses the innerserver_running?/open!stubs. I’m verifying the exact RuboCop behavior on a proper nested spec, then I’ll rewrite the malformed fixture into that real reproduction before patching the traversal.I’ve isolated the detection bug. The cop stops after reporting the outer
expect(subject).to receive(:fork) do ... end, so it never descends into that block and misses the innerserver_running?/open!stubs. I’m verifying the exact RuboCop behavior on a proper nested spec, then I’ll rewrite the malformed fixture into that real reproduction before patching the traversal.Task prompt (11326 tokens)
Fix RSpec/SubjectStub — 17 FP, 5 FN
Instructions
You are fixing ONE cop in nitrocop, a Rust Ruby linter that uses Prism for parsing.
Current state: 7,401 matches, 17 false positives, 5 false negatives.
Focus on: FP (nitrocop flags code RuboCop does not).
⚠ 7,401 existing matches must not regress. Validate with
check_cop.pybefore committing.Workflow
behavior on BOTH the specific FP case AND the general pattern:
tests/fixtures/cops/rspec/subject_stub/offense.rbwith^annotationtests/fixtures/cops/rspec/subject_stub/no_offense.rbcargo test --lib -- cop::rspec::subject_stubsrc/cop/rspec/subject_stub.rscargo test --lib -- cop::rspec::subject_stub///doc comment on the cop struct documenting what you found and fixedFixture Format
Mark offenses with
^markers on the line AFTER the offending source line.The
^characters must align with the offending columns. The message format isRSpec/SubjectStub: <message text>.See the Current Fixture sections below for real examples from this cop.
Mixed issues: some code bugs, some config issues
Pre-diagnostic shows SOME patterns are correctly detected in isolation (config issues)
and SOME are genuinely missed (code bugs). See the per-example diagnosis below.
If your test passes immediately
If you add a test case and it passes without code changes, the corpus mismatch is
caused by config/context differences, not a detection bug.
Do NOT loop trying to make the test fail. Instead:
src/config/or the cop's config handling, not detection logica
///comment on the cop struct and commitCRITICAL: Avoid regressions in the opposite direction
When fixing FPs, your change MUST NOT suppress legitimate detections. When fixing FNs,
your change MUST NOT flag code that RuboCop accepts. A fix that eliminates a few issues
in one direction but introduces hundreds in the other is a catastrophic regression.
Before exempting a category of patterns, verify with RuboCop that the general case
is still an offense:
If RuboCop flags the general pattern but not your specific case, the difference is in
a narrow context (e.g., enclosing structure, receiver type, argument count) — your fix
must target that specific context, not the broad category.
Rule of thumb: if your fix adds an early
returnorcontinuethat skips a wholenode type, operator class, or naming pattern, it's probably too broad. Prefer adding a
condition that matches the SPECIFIC differentiating context.
Rules
src/cop/rspec/subject_stub.rsandtests/fixtures/cops/rspec/subject_stub/cargo test --lib -- cop::rspec::subject_stubto verify your fix (do NOT run the full test suite)python3 scripts/check_cop.py RSpec/SubjectStub --rerun --clone --sample 15before committing to catch regressionsgit stashPrism Notes
Foo) and ConstantPathNode (qualifiedFoo::Bar). If you handle one, check if you need the other.begin..endis BeginNode, implicit method body is StatementsNode. Check which one(s) your cop needs.Current Fixture: offense.rb
tests/fixtures/cops/rspec/subject_stub/offense.rbCurrent Fixture: no_offense.rb
tests/fixtures/cops/rspec/subject_stub/no_offense.rbKey Source Files
src/cop/rspec/subject_stub.rsvendor/rubocop-rspec/lib/rubocop/cop/rspec/subject_stub.rbvendor/rubocop-rspec/spec/rubocop/cop/rspec/subject_stub_spec.rbRead these files before making changes.
Start Here
Use the existing corpus data to focus on the most concentrated regressions first.
Helpful local commands:
python3 scripts/investigate_cop.py RSpec/SubjectStub --repos-onlypython3 scripts/investigate_cop.py RSpec/SubjectStub --contextpython3 scripts/verify_cop_locations.py RSpec/SubjectStubTop FP repos:
discourse__docker_manager__370ca86(11 FP) — examplespec/support/shared_examples/web_server_adapter.rb:10mysociety__alaveteli__d5b834f(4 FP) — examplespec/models/project_spec.rb:342ubicloud__ubicloud__b181cb6(2 FP) — examplespec/prog/vm/host_nexus_spec.rb:173Top FN repos:
DannyBen__madness__5e61446(5 FN) — examplespec/madness/browser_spec.rb:47Representative FP examples:
discourse__docker_manager__370ca86: spec/support/shared_examples/web_server_adapter.rb:10— Do not stub methods of the object under test.discourse__docker_manager__370ca86: spec/support/shared_examples/web_server_adapter.rb:47— Do not stub methods of the object under test.discourse__docker_manager__370ca86: spec/support/shared_examples/web_server_adapter.rb:61— Do not stub methods of the object under test.Representative FN examples:
DannyBen__madness__5e61446: spec/madness/browser_spec.rb:47— Do not stub methods of the object under test.DannyBen__madness__5e61446: spec/madness/browser_spec.rb:60— Do not stub methods of the object under test.DannyBen__madness__5e61446: spec/madness/browser_spec.rb:61— Do not stub methods of the object under test.Pre-diagnostic Results
Diagnosis Summary
Each example was tested by running nitrocop on the extracted source in isolation
with
--force-default-configto determine if the issue is a code bug or config issue.Note: source context is truncated and may not parse perfectly. If a diagnosis
seems wrong (e.g., your test passes immediately for a 'CODE BUG'), treat it as
a config/context issue instead.
FN #1:
DannyBen__madness__5e61446: spec/madness/browser_spec.rb:47NOT DETECTED — CODE BUG
The cop fails to detect this pattern. Fix the detection logic.
Full-file enclosing chain: block (do..end) (line 46:
expect(subject).to receive(:fork) do |&block|) > block (do..end) (line 45:it 'yields an error message' do) > block (do..end) (line 44:context 'when the server is not running' do) > block (do..end) (line 43:describe '#open' do) > block (do..end) (line 1:describe Browser do)Prism AST at offense line:
StatementsNode > CallNode > CallNode > ArgumentsNode > CallNode > ArgumentsNode > CallNode > CallNode > ArgumentsNode > SymbolNode > ArgumentsNode > FalseNodeMessage:
Do not stub methods of the object under test.Ready-made test snippet (add to offense.rb, adjust
^count):Full file context (30 lines before offense):
FN #2:
DannyBen__madness__5e61446: spec/madness/browser_spec.rb:60NOT DETECTED — CODE BUG
The cop fails to detect this pattern. Fix the detection logic.
Full-file enclosing chain: block (do..end) (line 59:
expect(subject).to receive(:fork) do |&block|) > block (do..end) (line 58:it 'yields an error message' do) > block (do..end) (line 57:context 'when the server is running but the launch command fails' do) > block (do..end) (line 43:describe '#open' do) > block (do..end) (line 1:describe Browser do)Prism AST at offense line:
StatementsNode > CallNode > CallNode > ArgumentsNode > CallNode > ArgumentsNode > CallNode > CallNode > ArgumentsNode > SymbolNode > ArgumentsNode > TrueNodeMessage:
Do not stub methods of the object under test.Ready-made test snippet (add to offense.rb, adjust
^count):Full file context (30 lines before offense):
FN #3:
DannyBen__madness__5e61446: spec/madness/browser_spec.rb:61NOT DETECTED — CODE BUG
The cop fails to detect this pattern. Fix the detection logic.
Full-file enclosing chain: block (do..end) (line 59:
expect(subject).to receive(:fork) do |&block|) > block (do..end) (line 58:it 'yields an error message' do) > block (do..end) (line 57:context 'when the server is running but the launch command fails' do) > block (do..end) (line 43:describe '#open' do) > block (do..end) (line 1:describe Browser do)Prism AST at offense line:
CallNode > CallNode > ArgumentsNode > CallNode > ArgumentsNode > CallNode > CallNode > ArgumentsNode > SymbolNode > ArgumentsNode > FalseNodeMessage:
Do not stub methods of the object under test.Ready-made test snippet (add to offense.rb, adjust
^count):Full file context (30 lines before offense):
FN #4:
DannyBen__madness__5e61446: spec/madness/browser_spec.rb:73NOT DETECTED — CODE BUG
The cop fails to detect this pattern. Fix the detection logic.
Full-file enclosing chain: block (do..end) (line 72:
expect(subject).to receive(:fork) do |&block|) > block (do..end) (line 71:it 'yields nil' do) > block (do..end) (line 70:context 'when the server is running and the launch command succeeds' do) > block (do..end) (line 43:describe '#open' do) > block (do..end) (line 1:describe Browser do)Prism AST at offense line:
StatementsNode > CallNode > CallNode > ArgumentsNode > CallNode > ArgumentsNode > CallNode > CallNode > ArgumentsNode > SymbolNode > ArgumentsNode > TrueNodeMessage:
Do not stub methods of the object under test.Ready-made test snippet (add to offense.rb, adjust
^count):Full file context (30 lines before offense):
FN #5:
DannyBen__madness__5e61446: spec/madness/browser_spec.rb:74NOT DETECTED — CODE BUG
The cop fails to detect this pattern. Fix the detection logic.
Full-file enclosing chain: block (do..end) (line 72:
expect(subject).to receive(:fork) do |&block|) > block (do..end) (line 71:it 'yields nil' do) > block (do..end) (line 70:context 'when the server is running and the launch command succeeds' do) > block (do..end) (line 43:describe '#open' do) > block (do..end) (line 1:describe Browser do)Prism AST at offense line:
CallNode > CallNode > ArgumentsNode > CallNode > ArgumentsNode > CallNode > CallNode > ArgumentsNode > SymbolNode > ArgumentsNode > TrueNodeMessage:
Do not stub methods of the object under test.Ready-made test snippet (add to offense.rb, adjust
^count):Full file context (30 lines before offense):
FP #1:
discourse__docker_manager__370ca86: spec/support/shared_examples/web_server_adapter.rb:10NOT REPRODUCED — CONFIG/CONTEXT issue
nitrocop does not flag this in isolation or in the full file
(with default config). The FP is caused by the target repo's
config (e.g., different Max value, Include/Exclude patterns).
Source context:
Message:
Do not stub methods of the object under test.Full file context (30 lines before offense):
FP #2:
discourse__docker_manager__370ca86: spec/support/shared_examples/web_server_adapter.rb:47NOT REPRODUCED — CONFIG/CONTEXT issue
nitrocop does not flag this in isolation or in the full file
(with default config). The FP is caused by the target repo's
config (e.g., different Max value, Include/Exclude patterns).
Source context:
Message:
Do not stub methods of the object under test.Full file context (30 lines before offense):
FP #3:
discourse__docker_manager__370ca86: spec/support/shared_examples/web_server_adapter.rb:61NOT REPRODUCED — CONFIG/CONTEXT issue
nitrocop does not flag this in isolation or in the full file
(with default config). The FP is caused by the target repo's
config (e.g., different Max value, Include/Exclude patterns).
Source context:
Message:
Do not stub methods of the object under test.Full file context (30 lines before offense):
FP #4:
discourse__docker_manager__370ca86: spec/support/shared_examples/web_server_adapter.rb:95NOT REPRODUCED — CONFIG/CONTEXT issue
nitrocop does not flag this in isolation or in the full file
(with default config). The FP is caused by the target repo's
config (e.g., different Max value, Include/Exclude patterns).
Source context:
Message:
Do not stub methods of the object under test.Full file context (30 lines before offense):
FP #5:
discourse__docker_manager__370ca86: spec/support/shared_examples/web_server_adapter.rb:101NOT REPRODUCED — CONFIG/CONTEXT issue
nitrocop does not flag this in isolation or in the full file
(with default config). The FP is caused by the target repo's
config (e.g., different Max value, Include/Exclude patterns).
Source context:
Message:
Do not stub methods of the object under test.Full file context (30 lines before offense):
FP #6:
discourse__docker_manager__370ca86: spec/support/shared_examples/web_server_adapter.rb:102NOT REPRODUCED — CONFIG/CONTEXT issue
nitrocop does not flag this in isolation or in the full file
(with default config). The FP is caused by the target repo's
config (e.g., different Max value, Include/Exclude patterns).
Source context:
Message:
Do not stub methods of the object under test.Full file context (30 lines before offense):
FP #7:
discourse__docker_manager__370ca86: spec/support/shared_examples/web_server_adapter.rb:109NOT REPRODUCED — CONFIG/CONTEXT issue
nitrocop does not flag this in isolation or in the full file
(with default config). The FP is caused by the target repo's
config (e.g., different Max value, Include/Exclude patterns).
Source context:
Message:
Do not stub methods of the object under test.Full file context (30 lines before offense):
FP #8:
discourse__docker_manager__370ca86: spec/support/shared_examples/web_server_adapter.rb:132NOT REPRODUCED — CONFIG/CONTEXT issue
nitrocop does not flag this in isolation or in the full file
(with default config). The FP is caused by the target repo's
config (e.g., different Max value, Include/Exclude patterns).
Source context:
Message:
Do not stub methods of the object under test.Full file context (30 lines before offense):
Omitted 7 additional diagnosed FP example(s) for brevity.