1

I've created Pundit policies specs with

rails g pundit:policy class

... but the specs are giving the following error:

.rvm/gems/ruby-2.2.2/gems/rspec-core-3.3.1/lib/rspec/core/memoized_helpers.rb:287:in `let': #let or #subject called without a block (RuntimeError)
from .rvm/gems/ruby-2.2.2/gems/rspec-core-3.3.1/lib/rspec/core/memoized_helpers.rb:405:in `subject'
from spec/policies/application_policy_spec.rb:10:in `block (2 levels) in <top (required)>'

But in the spec it seems the subject is being called with a block. Here is the spec generated:

require 'rails_helper'

describe ApplicationPolicy do

  let(:user) { User.new }

  subject { described_class }

  permissions :index do
    expect(subject).to permit(user)
  end

  permissions :show? do
    pending "add some examples to (or delete) #{__FILE__}"
  end

  permissions :create? do
    pending "add some examples to (or delete) #{__FILE__}"
  end

  permissions :update? do
    pending "add some examples to (or delete) #{__FILE__}"
  end

  permissions :destroy? do
    pending "add some examples to (or delete) #{__FILE__}"
  end
end

Any ideas?

Hugo Carlos
  • 401
  • 3
  • 22

1 Answers1

2

I've figured it out. I was missing the ? in the index actions and had to create an it block inside the permissions block, like that:

  permissions :index? do
    it 'allows users to index' do  
      expect(subject).to permit(user)
    end
  end
Hugo Carlos
  • 401
  • 3
  • 22