Skip to content

Conversation

@sadahiro-ono
Copy link

@sadahiro-ono sadahiro-ono commented Feb 9, 2026

Add except option to assert_request_schema_confirm to allow
intentionally omitting required parameters when testing error responses
(401, 400, etc.) while still validating other parameters.

Features

  • Exclude specific parameters from validation by type (headers, query, path, body)
  • Support multiple parameters in each type simultaneously
  • Validate that non-excepted parameters still raise errors when missing

Implementation

  • Add ExceptParameter class with handler pattern for each param type
  • Refactor QueryHandler, PathHandler, BodyHandler using BaseHashParameterHandler
    to eliminate code duplication (DRY principle)
  • Use rack.request.query_hash for query parameters with ||= initialization
  • Use prefixed keys (e.g., query:page, path:id) in original_values hash to:
    • Distinguish parameters with same names in different locations
    • Identify correct storage location during restoration
  • Store original values before applying dummy values and restore them after validation to:
    • Prevent test environment pollution (dummy values leaking between tests)
    • Maintain test independence and avoid flaky tests
    • Ensure restoration even when validation raises errors (using ensure block)

Tests

  • Add comprehensive test cases for all parameter types
  • Add /test_except_validation endpoint for testing except behavior
  • Verify non-excepted parameters still raise validation errors

Documentation

  • Add usage examples with generic parameter names to README.md
  • Document except option for error response testing scenarios
  • Add YARD documentation following committee gem conventions

Add `except` option to `assert_request_schema_confirm` to allow
intentionally omitting required parameters when testing error responses
(401, 400, etc.) while still validating other parameters.

Features:
- Exclude specific parameters from validation by type (headers, query,
  path, body)
- Support multiple parameters in each type simultaneously
- Validate that non-excepted parameters still raise errors when missing

Implementation:
- Add ExceptParameter class with handler pattern for each param type
- Refactor QueryHandler, PathHandler, BodyHandler using
  BaseHashParameterHandler to eliminate code duplication (DRY principle)
- Use rack.request.query_hash for query parameters with ||= initialization
- Properly restore original values after validation using ensure block

Tests:
- Add comprehensive test cases for all parameter types
- Add /test_except_validation endpoint for testing except behavior
- Verify non-excepted parameters still raise validation errors

Documentation:
- Add usage examples with generic parameter names to README.md
- Document except option for error response testing scenarios
@sadahiro-ono sadahiro-ono marked this pull request as draft February 10, 2026 01:28
@sadahiro-ono sadahiro-ono marked this pull request as ready for review February 10, 2026 01:44
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.

1 participant