title: Is there any way to mock Pundit policy authorize in request specs?
body: <p>I am using Pundit for authorization on my Rails app and I am unit testing my requests. 
  I have already successfully tested the policy but now I want to verify that my request is using that policy. 
  I want to do it in a generic way, that I can use in ANY request spec (regardless of the controller, the action, and the policy). 
  To be honest at this point I would be conformed with a way of saying "expect any policy to receive authorize", generic to all requests. </p>
  
  <p>For the index action (that uses the policy scope) it was easy:</p>
  
  <p>In the request describe I say </p>
  
  <pre><code>RSpec.describe 'GET /companies', type: :request do
    include_context 'invokes policy scope'
  end
  </code></pre>
  
  <p>And then I defined the shared context as:</p>
  
  <pre><code>RSpec.shared_context 'invokes policy scope', shared_context: :metadata do
    before do
      expect(Pundit).to receive(:policy_scope!) do |user_context, relation|
        expect(user_context.user).to eq(user)
        expect(user_context.current_group).to eq(group)
  
        relation
      end
    end
  end
  </code></pre>
  
  <p>But how do I do the same for the authorize method. I don't know which concrete policy will be the one receiving it, neither which is the concrete controller that will invoke the <code>authorize</code>. </p>
  
  <p>I don't understand how pundit does not provide a custom matcher to verify a certain request is actually invoking a given policy, or to "simulate" authorized/unauthorized scenarios so I test that my request returns the correct status code. </p>
  
  <p>Any ideas?</p>