开发者

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

开发者 https://www.devze.com 2022-12-20 14:10 出处:网络
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?If you are getting \

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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消