module Pundit::RSpec::Matchers
Namespace for Pundit’s RSpec
matchers.
Attributes
Used to build a suitable description for the Pundit
‘permit` matcher. @api public @param value [String, Proc] @example
Pundit::RSpec::Matchers.description = ->(user, record) do "permit user with role #{user.role} to access record with ID #{record.id}" end
Public Class Methods
Source
# File lib/pundit/rspec.rb, line 27 def description(user, record) return @description.call(user, record) if defined?(@description) && @description.respond_to?(:call) @description end
Used to retrieve a suitable description for the Pundit
‘permit` matcher. @api private @private
Public Instance Methods
Source
# File lib/pundit/rspec.rb, line 88 def current_example ::RSpec.current_example end
Source
# File lib/pundit/rspec.rb, line 100 def permissions current_example.metadata.fetch(:permissions) do raise KeyError, <<~ERROR.strip No permissions in example metadata, did you forget to wrap with `permissions :show?, ...`? ERROR end end
Source
# File lib/pundit/rspec.rb, line 60 def was_or_were if @violating_permissions.count > 1 "were" else "was" end end