Skip to content

Commit

Permalink
fix: check for NoMethodError instead of NotImplementedError (#545)
Browse files Browse the repository at this point in the history
[Pundit have recently
changed](varvet/pundit#776) to using
`NoMethodError`, which breaks our spec - the main benefit of this change
is that the new error extends from `StandardError` so in theory is
easier to catch; however, it seems the community is divided as aside
from the different superclass the existing error is more accurate since
`NoMethodError` is meant to be thrown when the class does not
`respond_to?` the method in question and that is not true.

I personally would like to keep using `NotImplementedError` though I'm
happy to change if someone does prove a real-world situation where it's
more burdson to catch (or that our error monitoring won't catch it), but
I feel that should be a separate conversation - so this PR is changing
it back to maintain our current status quo until such time that we do
decide to change.
  • Loading branch information
G-Rath committed May 31, 2024
1 parent 62828a6 commit 7011368
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions variants/pundit/template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
run "rails g pundit:install"
run "rails g pundit:policy example"

# Pundit uses NoMethodError which is easier to catch as it extends from StandardError,
# but it's technically not correct as our class does respond to the method in question
#
# For now, we're just going to stick with the more traditional error for this situation
gsub_file! "app/policies/application_policy.rb", "raise NoMethodError", "raise NotImplementedError"

copy_file "spec/policies/example_policy_spec.rb", force: true
copy_file "spec/policies/application_policy_spec.rb", force: true

Expand Down

0 comments on commit 7011368

Please sign in to comment.