ruby-on-railsactionviewactionviewhelper

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?


Solution

  • 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"