title: Why pundit can't find policies in controller tests?
body: <p>The controller:</p>
  
  <pre><code>class UsersController &lt; ApplicationController
    def index
      ...
      authorize User
    end
    ...
  </code></pre>
  
  <p>The policy:</p>
  
  <pre><code>class UserPolicy &lt; ApplicationPolicy
    def index
      @user.admin?
    end
  end
  </code></pre>
  
  <p>The test:</p>
  
  <pre><code>class UsersControllerAuthorizationTest &lt; ActionController::TestCase
    tests :users
  
    def user
      @user ||= create(:user)
    end
  
    test 'should not authorize ordinary users to access the page' do
      sign_in user
      get :index
      assert_response :error
    end
  end
  </code></pre>
  
  <p>The app fails with <code>Pundit::NotAuthorizedError (not allowed to index? this User)</code> as expected. But the test says:</p>
  
  <pre><code>Pundit::NotDefinedError: unable to find policy UserPolicy for User
  </code></pre>
  
  <p>Am I doing it wrong? Can I make it find the policy?</p>
  
  <p><strong>UPD</strong> It must have to do with <code>rails</code>' autoloading. Calling <a href="https://github.com/elabs/pundit/blob/v0.3.0/lib/pundit/policy_finder.rb#L17" rel="nofollow"><code>constantize</code></a> on <code>'UserPolicy'</code> makes it autoload <code>app/policies/user_policy.rb</code> in case of the app, and doesn't, in case of the tests.</p>
  
  <p><strong>UPD</strong> The problem supposedly laid in <code>spring</code>. After stopping it, the tests now output:</p>
  
  <pre><code>Pundit::NotAuthorizedError: not allowed to index? this User
  </code></pre>