Skip to content

Instantly share code, notes, and snippets.

@RaZer
Created April 17, 2014 15:54
Show Gist options
  • Save RaZer/10993850 to your computer and use it in GitHub Desktop.
Save RaZer/10993850 to your computer and use it in GitHub Desktop.
module PunditMatchers
extend ::RSpec::Matchers::DSL
matcher :permit do |action|
match do |policy|
policy.public_send("#{action}?")
end
failure_message_for_should do |policy|
"Expected #{policy.class} to permit :#{action} on #{policy.record} for #{policy.user.inspect}."
end
failure_message_for_should_not do |policy|
"Expected #{policy.class} to forbid :#{action} on #{policy.record} for #{policy.user.inspect}."
end
end
end
RSpec.configure do |c|
c.include PunditMatchers, type: :policy
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment