varvet / pundit

Minimal authorization through OO design and pure Ruby classes
MIT License
8.21k stars 624 forks source link

Enable custom description for permit matcher #759

Closed barelyknown closed 1 month ago

barelyknown commented 1 year ago

We're using RSpec output to document the permissions of all our resources. The default description is not what we want since it inspects the user and that adds noise to the output for no value.

I understand that it's probably not reasonable to change the default description because some people may depend on that behavior. But, it would be good to add the ability to customize it.

For example, I added a:

module Pundit
  module RSpec
    module Matchers
      extend ::RSpec::Matchers::DSL
      def self.description(&block)
        @description = block.call
      end
      # ...
      matcher :permit do |user, record|
        # ...
        description do
          if Pundit::RSpec::Matchers.instance_variable_defined?(:@description)
            Pundit::RSpec::Matchers.instance_variable_get(:@description)
          else
            super
          end
        end
      # ...
end

If you're interested in a related PR, I'll send one in.