title: How to test a controller action that does not exist?
body: <p>There are only two actions accessible in the <code>ProductsController</code>:</p>
  
  <pre class="lang-ruby prettyprint-override"><code># /config/routes.rb
  RailsApp::Application.routes.draw do
    resources :products, only: [:index, :show]
  end
  </code></pre>
  
  <p>Tests are set up accordingly:</p>
  
  <pre class="lang-ruby prettyprint-override"><code># /spec/controllers/products_controller_spec.rb
  require 'spec_helper'
  
  describe ProductsController do
  
    before do
      @product = Product.gen
    end
  
    describe "GET index" do
      it "renders the index template" do
        get :index
        expect(response.status).to eq(200)
        expect(response).to render_template(:index)
      end
    end
  
    describe "GET show" do
      it "renders the show template" do
        get :show, id: @product.id
        expect(response.status).to eq(200)
        expect(response).to render_template(:show)
      end
    end
  
  end
  </code></pre>
  
  <p>How would you test that the other <a href="http://guides.rubyonrails.org/routing.html#crud-verbs-and-actions" rel="nofollow noreferrer">CRUD actions</a> are <strong>not</strong> accessible? This might change in the future so the tests will ensure any configuration change will be noticed.<br>
  I found the <a href="https://www.relishapp.com/rspec/rspec-rails/docs/routing-specs/be-routable-matcher" rel="nofollow noreferrer"><code>be_routable</code> matcher</a> which looks promising to cover the test case.</p>
  
  <hr>
  
  <p>I recommend this <a href="https://stackoverflow.com/a/18117630/356895">post by Dave Newton which describes when and why to test controller actions</a>.</p>