Skip to content

fix: safely extract request/response when let() overrides exist#294

Open
AlexeyMatskevich wants to merge 4 commits intoexoego:masterfrom
AlexeyMatskevich:fix/request-response-let-overrides
Open

fix: safely extract request/response when let() overrides exist#294
AlexeyMatskevich wants to merge 4 commits intoexoego:masterfrom
AlexeyMatskevich:fix/request-response-let-overrides

Conversation

@AlexeyMatskevich
Copy link
Copy Markdown
Contributor

@AlexeyMatskevich AlexeyMatskevich commented Dec 24, 2025

Summary

  • Fixes OpenAPI extraction when users define let(:request) or let(:response) in their specs
  • Prioritizes integration_session if available for request/response extraction
  • Falls back to detecting RSpec memoized helpers and calling super_method to get actual objects

Test plan

  • Added integration test that defines let(:request) and let(:response) overrides
  • Test verifies OpenAPI record is still generated with correct status code

Related issue #251

Comment thread lib/rspec/openapi/extractors/rails.rb Fixed
Comment thread lib/rspec/openapi/extractors/rails.rb Fixed
When users define `let(:request)` or `let(:response)` in their specs,
the context methods would return those stubbed values instead of the
actual ActionDispatch objects. This caused OpenAPI extraction to fail.

The fix prioritizes the integration_session if available, then falls
back to checking if the method is defined by RSpec memoization helpers
and calls the super_method to get the real request/response objects.
@AlexeyMatskevich AlexeyMatskevich force-pushed the fix/request-response-let-overrides branch from 49647c5 to 36336cd Compare December 24, 2025 04:08
…verification

Replace indirect after(:context) verification with a dedicated /override_probe
endpoint and inline RSpec::OpenAPI::RecordBuilder.build call. This makes the
test self-contained and easier to understand.
@codecov
Copy link
Copy Markdown

codecov bot commented Dec 24, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.93%. Comparing base (9a40e01) to head (9bdeda6).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #294      +/-   ##
==========================================
+ Coverage   98.91%   98.93%   +0.02%     
==========================================
  Files          20       20              
  Lines         735      751      +16     
  Branches      188      195       +7     
==========================================
+ Hits          727      743      +16     
  Misses          8        8              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Add explicit tests for the request_response extraction logic:
- Test that integration_session is used when available
- Test fallback to instance variables when integration_session returns nil

it 'calls regular methods directly', openapi: false do
context = Object.new
def context.custom_method; :value; end

Check notice

Code scanning / Rubocop

Avoid single-line methods. Note test

Style/SingleLineMethods: Avoid single-line method definitions.
Add tests for uncovered branches in safe_context_method and
integration_session to improve branch coverage from ~66% to 80%.

Covers:
- respond_to? returning false
- method.call for non-RSpec owned methods
- integration_session returning nil
- NameError rescue path
@AlexeyMatskevich AlexeyMatskevich force-pushed the fix/request-response-let-overrides branch from 9d99ca1 to 9bdeda6 Compare December 24, 2025 07:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants