lib/pundit/matchers.rb in pundit-matchers-1.2.3 vs lib/pundit/matchers.rb in pundit-matchers-1.3.0

- old
+ new

@@ -1,12 +1,16 @@ require 'rspec/core' module Pundit module Matchers - RSpec::Matchers.define :forbid_action do |action| + RSpec::Matchers.define :forbid_action do |action, *args| match do |policy| - !policy.public_send("#{action}?") + if args.any? + !policy.public_send("#{action}?", *args) + else + !policy.public_send("#{action}?") + end end failure_message do |policy| "#{policy.class} does not forbid #{action} on #{policy.record} for " \ "#{policy.user.inspect}." @@ -126,12 +130,16 @@ "#{policy.class} does not permit the new or create action on " \ "#{policy.record} for #{policy.user.inspect}." end end - RSpec::Matchers.define :permit_action do |action| + RSpec::Matchers.define :permit_action do |action, *args| match do |policy| - policy.public_send("#{action}?") + if args.any? + policy.public_send("#{action}?", *args) + else + policy.public_send("#{action}?") + end end failure_message do |policy| "#{policy.class} does not permit #{action} on #{policy.record} for " \ "#{policy.user.inspect}."