RSpec "undefined local variable or method `user'"
- by Justin
I have the following test written in RSpec:
describe '#create' do
...
it 'redirects users to profile page' do
response.should redirect_to user_path(user)
end
...
...
And the following in my UsersController:
def create
@user = User.new(params[:user])
if @user.save
redirect_to user_path(@user)
end
end
Does anyone know why this is returning the following error:
NameError: undefined local variable or method 'user'
I also tried changing this to be root_url in both cases instead of user_path(user) and it gave a different error saying:
Expected response to be a <:redirect>, but was <200>
Does anyone know what the issue might be? I have double-checked my code and have seen similar questions posted online, but haven't been able to find a solution. Thanks in advance for any help!