Skip to content

Feature Request: Add except option to skip validation for specific parameters when testing error responses #470

@sadahiro-ono

Description

@sadahiro-ono

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: true
it '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)
end

Current 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)
end

Supported 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions