Created
October 15, 2015 09:52
-
-
Save lcguida/4282a46b7a05bb1e5fc3 to your computer and use it in GitHub Desktop.
Creates a `grant_permission_to` matcher to test Pundit policies.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# spec/support/pundit.rb | |
# Creates a 'grant_permission_to' matcher to better test Pundit policies | |
# See: http://thunderboltlabs.com/blog/2013/03/27/testing-pundit-policies-with-rspec/ | |
RSpec::Matchers.define :grant_permission_to do |action| | |
match do |policy| | |
policy.public_send("#{action}?") | |
end | |
description do | |
"grant permition to #{action}" | |
end | |
failure_message do |policy| | |
"#{policy.class} does not permit #{action} on #{policy.record} for #{policy.user.inspect}." | |
end | |
failure_message_when_negated do |policy| | |
"#{policy.class} does not forbid #{action} on #{policy.record} for #{policy.user.inspect}." | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment