title: Verify user authenticated for actions
body: <p>I'm using devise and want to check in my specs that certain controller actions are covered by <code>authenticate_user!</code></p>
  
  <p>I've looked over the devise docs, I feel there's something really simple and obvious I'm not getting about the way devise works.</p>
  
  <p>Based on <a href="https://stackoverflow.com/questions/20775737/how-can-i-spec-before-filters">this SO post</a> I built a spec to check this, but it doesn't seem to be working.</p>
  
  <p>When I run the spec, I get:</p>
  
  <pre><code> Failure/Error: expect(controller).to receive(:authenticate_user!)
  
     (#&lt;LibrariesController:0x000001035639f8&gt;).authenticate_user!(*(any args))
         expected: 1 time with any arguments
         received: 0 times with any arguments
  </code></pre>
  
  <p><strong>libraries_controller_spec.rb</strong></p>
  
  <pre><code>require 'rails_helper'
  
  RSpec.describe LibrariesController, type: :controller do
  
    let(:valid_attributes) {
      skip("Add a hash of attributes valid for your model")
    }
  
    let(:invalid_attributes) {
      skip("Add a hash of attributes invalid for your model")
    }
  
    let(:valid_session) { {} }
  
    describe "GET #index" do
      it "should be authenticated" do
        get :index, {}
        expect(controller).to receive(:authenticate_user!)
      end
    end
  end
  </code></pre>
  
  <p>And the controller itself:</p>
  
  <p><strong>libraries_controller.rb</strong></p>
  
  <pre><code>class LibrariesController &lt; ApplicationController
    before_action :set_library, only: [:show, :edit, :update, :destroy]
    before_action :authenticate_user!
  
    # GET /libraries
    # GET /libraries.json
    def index
      @libraries = Library.all
    end
  
    private
      # Use callbacks to share common setup or constraints between actions.
      def set_library
        @library = Library.find(params[:id])
      end
  end
  </code></pre>