testing helpers and routes in rails console

12/2/2016 update: REALLY GREAT BLOG POST.

I ran into a really annoying problem once. So annoying that when I had to do it again, I remembered how annoying it was. And how annoying it was that no one talked about it. No one will tell you this next bit. They want to keep it a secret so that you’ll want to punch a wall. But I like your walls, so I’ll tell you this little secret, how to test helpers in rails console.

Testing the number_to_human helper function in rails console

I want to test the number_to_human helper function to see if it meets my needs.

Open Console

$ rails c

 > number_to_human(123456789)
 > NoMethodError: undefined method `number_to_human' for main:Object

WTF right? It’s a method and I KNOW it exists. Here’s the secret, prepend the function with helper.

 > helper.number_to_human(123456789)
 => "123 million"

And all I can say is boom!

Routes within Console

$ rails c
> app.rabbits_path
=> "/rabbits"

Post Content