`permit` passes both `to` and `not_to` when a `permissions` group names no permissions
Describe the bug
With an empty permissions list, permit can't fail in either direction: match and match_when_negated both return @violating_permissions.empty? (lib/pundit/rspec.rb:42, :49), which is always true when there is nothing to check.
To Reproduce
require "bundler/inline"
gemfile do
source "https://rubygems.org"
gem "pundit", "2.5.2"
gem "rspec", "~> 3.13"
end
require "pundit/rspec"
require "rspec/autorun"
DenyAllPolicy = Struct.new(:user, :record) do
def destroy? = false
end
RSpec.describe DenyAllPolicy, type: :policy do
subject { described_class }
permissions :destroy? do
it { is_expected.to permit(nil, nil) } # fails, as it should
end
permissions do
it { is_expected.to permit(nil, nil) } # passes
it { is_expected.not_to permit(nil, nil) } # also passes
end
endRuby 4.0.4 on macOS 26.5, pundit 2.5.2, rspec 3.13: 3 examples, 1 failure. The named :destroy? example fails; both empty-group examples pass against a policy that denies everything. Same on main (a05c6f19).
Expected behavior
An error, the way a missing permissions wrapper raises KeyError since #836 (rspec.rb:103-108).
Additional context
The DSL passes the list through unchecked (rspec.rb:131-139). Raising from the matcher's permissions helper when the list is empty would leave empty groups that never call permit alone. Happy to open the PR with a spec and a CHANGELOG line.
Source: varvet/pundit