Skip to content

Instantly share code, notes, and snippets.

@bradgessler
Created November 29, 2014 04:43
Show Gist options
  • Save bradgessler/d5bfb9808ccee8a13e1b to your computer and use it in GitHub Desktop.
Save bradgessler/d5bfb9808ccee8a13e1b to your computer and use it in GitHub Desktop.
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
@bradgessler
Copy link
Author

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