Skip to content

Instantly share code, notes, and snippets.

@ericchernuka
Created March 11, 2014 14:56
Show Gist options
  • Save ericchernuka/9487484 to your computer and use it in GitHub Desktop.
Save ericchernuka/9487484 to your computer and use it in GitHub Desktop.
Pundit Matchers for Rspec 3.0
RSpec::Matchers.define :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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment