Search code examples
ruby-on-railsrspecrspec-rails

RSpec giving undefined method `key?' for controller testing


Trying to test my controller with RSpec how ever I am getting this error:

enter image description here

I looked at couple of stackoverflows but couldn't find the answer:

StackOverflowOne

StackOverflowTwo

StackOverflowThree

can some one please explain this error to me?

This is my Test case: enter image description here

This is my controller: enter image description here

This is my model: enter image description here


Solution

  • instead of post :create, app you need to post :create, id: app

    with this exception, ruby is trying to tell you that you passed something that is not quacking like a hash into the post method, so it does not have a key? method on app.

    i would like to recommend this article about debugging rails in development to you. it might help you improve your debugging skills.

    another note: if you post a question to stackoverflow, you should paste real code instead of screenshots so that it's searchable for others and easy to copy and paste into answers.