def index @user end 

How to check the value of the user variable when in the tests we move to the controller's index method?

  • Before or after performing the method? - D-side
  • If there is an instance of the controller class, then its instance_variable_get method can be used, that is, so: instance_of_controller.instance_variable_get(:@user) , after it has completed the index method - MAXOPKA

1 answer 1

Usually, the controller variables are checked using the rspek - assigns method, for example, for your case:

 get :index expect(assigns(:user)).to_not be_nil 

On the RelishApp site you can read more.