Ahmad Al-kheat
Ahmad Al-kheat

Reputation: 1795

How to make the test name match the controller name?

I have this users_controller

class Api::V1::UsersController < ApplicationController
  respond_to :json

  def show
    respond_with User.find(params[:id])
  end

end

The file is in app/controllers/api/v1/

And my test is :

class Api::V1::UsersControllerTest < ActionController::TestCase

  test '#show displays the specific user' do 
    @user = FactoryGirl.build(:user)

    get :show, id: @user.id
    assert_response :success
  end
end

The file is in test/controllers/api/v1

When I run the test I get this error :

NameError: uninitialized constant Api
/Users/Ahmad/rails_apps/json_api/test/controllers/api/v1/users_controller_test.rb:1:in `<top (required)>'

What's going on?

Thanks

Upvotes: 1

Views: 50

Answers (1)

NickGnd
NickGnd

Reputation: 5197

I think you miss

require 'test_helper'

at the top of your file. Give a try.

Upvotes: 1

Related Questions