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

22,516

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.

Share:
22,516
aressidi
Author by

aressidi

Updated on July 09, 2022

Comments

  • aressidi
    aressidi almost 2 years

    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?

  • aressidi
    aressidi about 14 years
    Yes! Thanks bta, that worked. I specified .to_s before calling .strip and that worked perfectly. It seems like the app runs fine without the .to_s, performing the strips and the downcases as planned. RSpec is clearly anal about the type. Thanks again.