-
Notifications
You must be signed in to change notification settings - Fork 1.1k
NoMethodError: undefined method `[]=' for nil:NilClass in unit test #839
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hey, I'm trying to do the same thing you are basically (Except starting with IntegrationTests with registration), and I had that error before but I no longer do. This is my test_helper.rb:
and my auth_controller_test.rb:
I keep getting 307 as response code from the post. |
Thanks @Blitzkev, what did you do to fix the []= for nil error? When you say you keep getting a 307 you mean where you assert_response 201? |
Hey, I think adding
Fixed that particular error for me, but like you said it was hard to troubleshoot. The 307 is from the post user_registration_url line, which makes the User.count assert fail (no user created) |
@davidjconnolly :
This was caused because Try running tests with the -vb option to see verbose output + full backtrace |
I was unable to change the requests environment variables, I think this is no longer supported in Would be good to hear from devise_token_auth devs with respect to this. |
Thanks @Blitzkev, I still can't get rid of the If I add:
To my class ActionDispatch::IntegrationTest block in my test helper, I get the same Here is my test_helper.rb
And my controller unit test:
I experimented with adding I also wasn't able to run
Any suggestions? |
I assume you're using Rails 5, if so the new preferred syntax is to use If your main application doesn't use SSL, then don't worry about messing with those settings. I don't think
|
I see, that worked, thanks for the explanation @Blitzkev. I'm coming from Rails 4 a few years back and apparently have some catching up to do! FYI my controller/model tests are passing without:
Are you using ActionDispatch for all your controller/integration testing? What tests do you have that inherit ActionController? Thanks again! |
Seems like we have an explanation here and also a lack of recent activity. Closing out for now. |
Hi, thanks for creating this awesome gem!
I'm trying to unit test my controllers and am getting an error I'm having a really hard time debugging. I've got devise_token_auth configured and am using all the default rails 5 testing gems.
I'm doing what I think is a pretty vanilla test case where I just want to get a list of companies for the currently logged in user. I've verified that the objects are being set up correctly and tried putting loggers/byebug in the controller, however the execution path never makes it that far. Something in my get call is failing but I have no idea what the error it's throwing means:
NoMethodError: undefined method
[]=' for nil:NilClass`Any suggestions?
test_helper.rb:
companies_controller_test.rb
rake test output:
The text was updated successfully, but these errors were encountered: