Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add except option for testing error responses#465

Open
sadahiro-ono wants to merge 2 commits intointeragent:master from
sadahiro-ono:add-except-option
Open

Add except option for testing error responses #465
sadahiro-ono wants to merge 2 commits intointeragent:master from
sadahiro-ono:add-except-option

Conversation

@sadahiro-ono
Copy link

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

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

1 participant

AltStyle によって変換されたページ (->オリジナル) /