title: Rails Pundit Policy Spec test failing with NoMethodError
body: <p>I have just started using Pundit for authorization in my current project along with the pundit-matchers gem.</p>
  
  <p>So far it seems to generally be working for me but I have a problem in my tests.</p>
  
  <p>I have generally tried to follow the examples in the <a href="https://github.com/chrisalley/pundit-matchers" rel="nofollow">pundit-matchers readme</a> and the Thunderbolt labs blog (<a href="http://thunderboltlabs.com/blog/2013/03/27/testing-pundit-policies-with-rspec/" rel="nofollow">http://thunderboltlabs.com/blog/2013/03/27/testing-pundit-policies-with-rspec/</a>).</p>
  
  <p>This is my policy file;</p>
  
  <pre><code>#app/policies/procedure_policy.rb
  class   ProcedurePolicy
      attr_reader :user, :procedure
  
      def initialize(user, procedure)
          @user = user
          @procedure = procedure
      end
  
      def index?
          user.admin?
      end
  
  end
  </code></pre>
  
  <p>And this is my policy_spec file</p>
  
  <pre><code>require 'rails_helper'
  
  describe ProcedurePolicy do
      subject {described_class.new(user, procedure)}
  
      let(:procedure) {FactoryGirl.create(:procedure)}
  
      context "for a guest" do
          let(:user) {nil}
          it {is_expected.not_to permit_action(:index)}
      end
  
      context "for a non-admin user" do
          let(:user) {FactoryGirl.create(:user)}
          it {is_expected.not_to permit_action(:index)}
      end
  
      context "for an admin user" do
          let(:user) {FactoryGirl.create(:admin_user)}
          it {is_expected.to permit_action(:index)}
      end
  
  end
  </code></pre>
  
  <p>2 of my 3 tests pass; The <code>"for a non-admin user"</code> and <code>"for an admin user"</code> ones. The <code>"for a guest"</code> test fails with </p>
  
  <pre><code>NoMethodError:
         undefined method `admin?' for nil:NilClass
  </code></pre>
  
  <p>Now I understand why. I'm passing <code>nil</code> to the <code>#index?</code> method of my ProcedurePolicy class which will not have an <code>#admin?</code> method. But all of the example specs I have found online do exactly this. What am I not seeing.</p>
  
  <p>Apologies if I'm missing something really obvious. I've been away from coding for a couple of years.</p>