1
0
Fork 0
mirror of https://github.com/varvet/pundit.git synced 2022-11-09 12:30:11 -05:00

Fix rspec3 matcher deprecations

This commit is contained in:
Johannes Barre 2014-06-27 22:39:59 +02:00
parent 509be500c3
commit 13df6f02c9

View file

@ -4,22 +4,34 @@ module Pundit
extend ::RSpec::Matchers::DSL
matcher :permit do |user, record|
match_for_should do |policy|
match_proc = lambda do |policy|
permissions.all? { |permission| policy.new(user, record).public_send(permission) }
end
match_for_should_not do |policy|
match_when_negated_proc = lambda do |policy|
permissions.none? { |permission| policy.new(user, record).public_send(permission) }
end
failure_message_for_should do |policy|
failure_message_proc = lambda do |policy|
"Expected #{policy} to grant #{permissions.to_sentence} on #{record} but it didn't"
end
failure_message_for_should_not do |policy|
failure_message_when_negated_proc = lambda do |policy|
"Expected #{policy} not to grant #{permissions.to_sentence} on #{record} but it did"
end
if respond_to?(:match_when_negated)
match(&match_proc)
match_when_negated(&match_when_negated_proc)
failure_message(&failure_message_proc)
failure_message_when_negated(&failure_message_when_negated_proc)
else
match_for_should(&match_proc)
match_for_should_not(&match_when_negated_proc)
failure_message_for_should(&failure_message_proc)
failure_message_for_should_not(&failure_message_when_negated_proc)
end
def permissions
current_example = ::RSpec.respond_to?(:current_example) ? ::RSpec.current_example : example
current_example.metadata[:permissions]