-
Notifications
You must be signed in to change notification settings - Fork 141
Description
Note: I have already submitted PR #465 with a working implementation. Opening this issue to discuss the feature and gather feedback.
Problem
When testing error responses (401, 400, etc.) with assert_request_schema_confirm, validation fails if required parameters are intentionally omitted.
Example:
paths:
/resources:
get:
parameters:
- name: Authorization
in: header
required: true
- name: page
in: query
required: trueit 'returns 401 when Authorization header is missing' do
get '/resources', params: { page: 1 }
# Cannot call assert_request_schema_confirm - fails because Authorization is missing
assert_response_schema_confirm(401)
endCurrent workaround: Skip assert_request_schema_confirm entirely.
Problem with this: Other parameters (like page) are not validated, reducing test reliability.
Proposed Solution
Add an except option to exclude specific parameters from validation:
it 'returns 401 when Authorization header is missing' do
get '/resources', params: { page: 1 }
# Exclude Authorization header, validate everything else
assert_request_schema_confirm(except: { header: ['Authorization'] })
assert_response_schema_confirm(401)
endSupported parameter types:
assert_request_schema_confirm(except: {
header: ['Authorization'],
query: ['page'],
path: ['id'],
body: ['optional_field']
})Benefits
- Test error responses while validating non-excepted parameters
- Detect parameter drift from schema in error scenarios
- Maintain test reliability
Implementation
The implementation in PR #465 temporarily injects dummy values for excepted parameters that are missing from the request before validation, then restores the original values afterward via an ensure block.
Would appreciate feedback on whether this aligns with the project's direction.