title: How to test exception raising in Rails/RSpec?
body: <p>There is the following code:</p>
  <pre><code>def index
      @car_types = car_brand.car_types
  end
  
  def car_brand
      CarBrand.find(params[:car_brand_id])
  rescue ActiveRecord::RecordNotFound
      raise Errors::CarBrandNotFound.new 
  end
  </code></pre>
  <p>I want to test it through RSpec. My code is:</p>
  <pre><code>it 'raises CarBrandNotFound exception' do
      get :index, car_brand_id: 0
      expect(response).to raise_error(Errors::CarBrandNotFound)
  end
  </code></pre>
  <p>CarBrand with id equaling 0 doesn't exist, therefore my controller code raises Errors::CarBrandNotFound, but my test code tells me that nothing was raised. How can I fix it? What do I wrong?</p>