Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call 'time_ago_in_words' from a FunctionalTest?

I'm using 'time_ago_in_words' function in a view, and I need to test the output in the FunctionalTest.

But the test can not see 'time_ago_in_words' helper function.

What should I do in order to use these helper methods from FunctionalTests?

like image 328
Raiden Avatar asked Feb 11 '10 16:02

Raiden


2 Answers

Include the ActionView::Helpers::DateHelper module in your test_helper.rb or test.rb files. And that's it, from the test console:

>> time_ago_in_words(3.minutes.from_now)
NoMethodError: undefined method `time_ago_in_words' for #<Object:0x3b0724>
from (irb):4
from /Users/blinq/.rvm/rubies/ruby-1.9.1-p376/bin/irb:15:in `<main>'
>> include ActionView::Helpers::DateHelper
=> Object
>> time_ago_in_words(3.minutes.from_now)
=> "3 minutes"
like image 90
jpemberthy Avatar answered Nov 02 '22 16:11

jpemberthy


I added on rails_helper.rb

config.include ActionView::Helpers::DateHelper

and work's, thank's @jpemberthy!

like image 27
rld Avatar answered Nov 02 '22 18:11

rld