You have to invoke the subject
explicitly since the implicit receiver only works for should
. More information here and here.
In your example, this should work:
describe PostPolicy do
subject { PostPolicy }
permissions :create? do
it "denies access if post is published" do
expect(subject).not_to permit(User.new(:admin => false), Post.new(:published => true))
end
it "grants access if post is published and user is an admin" do
expect(subject).not_to permit(User.new(:admin => true), Post.new(:published => true))
end
it "grants access if post is unpublished" do
expect(subject).not_to permit(User.new(:admin => false), Post.new(:published => false))
end
end
end