Skip to content

Conversation

@ericproulx
Copy link
Contributor

Fix before_each method to handle nil parameter correctly

Problem

When calling before_each(nil) to clear the before_each callbacks, a NoMethodError was raised because the code attempted to assign nil to @before_each instead of clearing the array.

Solution

  • Modified the before_each method in lib/grape/endpoint.rb to properly handle the nil parameter by clearing the @before_each array instead of assigning nil
  • Updated test expectations in spec/grape/endpoint_spec.rb to be more specific about error types (NameError vs NoMethodError) and include error message patterns for better test reliability

Changes

  • lib/grape/endpoint.rb: Added else clause to clear @before_each when new_setup is nil
  • spec/grape/endpoint_spec.rb: Updated error expectations to match specific error types and messages

Testing

All existing tests pass, and the fix ensures that before_each(nil) correctly clears the callbacks without raising an error.

@github-actions
Copy link

github-actions bot commented Jan 27, 2026

Danger Report

No issues found.

View run

- Fix NoMethodError when calling before_each(nil) by clearing the array instead of assigning nil
- Update test expectations to be more specific about error types and messages
@ericproulx ericproulx force-pushed the fix_before_each_no_method_error branch from e340569 to f31f01d Compare January 27, 2026 21:07
@dblock dblock merged commit d333204 into master Jan 28, 2026
101 checks passed
@dblock dblock deleted the fix_before_each_no_method_error branch January 28, 2026 02:26
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.

3 participants