Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why am I getting undefined method errors for "strip" and "downcase" when I run RSpec on my models?

I am running an RSpec test on a model and getting errors for string methods such as: "index, "downcase," and "strip." Any ideas why that is and how I can fix it?

like image 482
aressidi Avatar asked Feb 12 '10 23:02

aressidi


1 Answers

If you are getting "undefined method", then the object you are operating on is likely not a string. Try printing out the result from .class before calling .strip, etc and see what type of object you are working with. A function that normally returns a string might return a non-string (like nil) on error, and you may be operating on something like that inadvertently.

like image 73
bta Avatar answered Sep 23 '22 23:09

bta