pundit-matchers
pundit-matchers copied to clipboard
Exceptions in policy creation
Hi,
I followed the advice in the pundit docs regarding closed systems, i.e., raising an exception when initializing the policy class. With this, a forbid_actions test fails, but I think it should pass. I currently use is_expected.to raise_error
, but could be nicer if I didn't have to worry how exactly the action was forbidden
Thanks!
Yes I agree that Pundit Matchers should support exceptions in policies. We will need to prepare a PR to include support for failure by exception in the matchers. The permit matchers, along with forbid matchers, should have tests for this feature.
The solution proposed in https://github.com/punditcommunity/pundit-matchers/issues/39#issuecomment-1352644741 is to add support for multiple ways of failing, with "any" being the default. This would be a breaking change, requiring a major version bump. I'll close this issue and we can move further discussion to #39.