0
votes

I'm using rspec-rails (3.7.1) with rails (5.1.4)

All the tests run successfully, but after adding namespace to routes.rb file, I got this error:

An error occurred while loading ./spec/controllers/stores_controller_spec.rb.
Failure/Error:
RSpec.describe StoresController, type: :controller do

NameError:
  uninitialized constant StoresController

and this is my routes.rb file:

namespace 'api' do
 namespace 'v1' do
  resources :stores
 end
end

where my stores_controller_spec.rb is

require 'rails_helper'

RSpec.describe StoresController, type: :controller do
 let(:store) { FactoryBot.create(:store) }

 describe "GET index" do
     it 'has a 200 status code' do
         request.headers.merge!(auth_headers)
         get :index
         expect(response.status).to eq(200)
     end
 end
end
1
Your controller might be Api::V1::StoresController. - Jagdeep Singh
@JagdeepSingh I tried this 2 minutes ago, it worked! Please retype your comment as answer to accept it. - MEH

1 Answers

2
votes

When you have a controller route namespace like

api/v1/stores

then Rails expects the controller to be named

Api::V1::StoresController 

and to be located in a file named

app/controllers/api/v1/stores_controller.rb