Created
November 29, 2014 04:43
-
-
Save bradgessler/d5bfb9808ccee8a13e1b to your computer and use it in GitHub Desktop.
RSpec 3 compatible Pundit matcher ported from http://thunderboltlabs.com/blog/2013/03/27/testing-pundit-policies-with-rspec/
This file contains hidden or 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
module PunditExampleGroup | |
extend ::RSpec::Matchers::DSL | |
matcher :permit do |action| | |
match do |policy| | |
policy.public_send("#{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 | |
end | |
RSpec.configure do |config| | |
config.include(PunditExampleGroup, { | |
:type => :policy, | |
:file_path => /spec\/policies/, | |
}) | |
end |
Great! Thanks for writing the original article. It was super helpful.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey Brad - thanks for writing this up. I'll add this to my "todo" list.