title: How to test a Controller Concern in Rails 4
body: <p>What is the best way to handle testing of concerns when used in Rails 4 controllers? Say I have a trivial concern <code>Citations</code>.</p>
  
  <pre><code>module Citations
      extend ActiveSupport::Concern
      def citations ; end
  end
  </code></pre>
  
  <p>The expected behavior under test is that any controller which includes this concern would get this <code>citations</code> endpoint.</p>
  
  <pre><code>class ConversationController &lt; ActionController::Base
      include Citations
  end
  </code></pre>
  
  <p>Simple.</p>
  
  <pre><code>ConversationController.new.respond_to? :yelling #=&gt; true
  </code></pre>
  
  <p>But what is the right way to test this concern in isolation? </p>
  
  <pre><code>class CitationConcernController &lt; ActionController::Base
      include Citations
  end
  
  describe CitationConcernController, type: :controller do
      it 'should add the citations endpoint' do
          get :citations
          expect(response).to be_successful
      end
  end
  </code></pre>
  
  <p>Unfortunately, this fails.</p>
  
  <pre><code>CitationConcernController
    should add the citations endpoint (FAILED - 1)
  
  Failures:
  
    1) CitationConcernController should add the citations endpoint
       Failure/Error: get :citations
       ActionController::UrlGenerationError:
         No route matches {:controller=&gt;"citation_concern", :action=&gt;"citations"}
       # ./controller_concern_spec.rb:14:in `block (2 levels) in &lt;top (required)&gt;'
  </code></pre>
  
  <p>This is a contrived example. In my app, I get a different error.</p>
  
  <pre><code>RuntimeError:
    @routes is nil: make sure you set it in your test's setup method.
  </code></pre>