如何从FunctionalTest中调用'time_ago_in_words'?

Rai*_*den 17 ruby-on-rails actionview actionviewhelper

我在视图中使用'time_ago_in_words'函数,我需要在FunctionalTest中测试输出.

但测试无法看到'time_ago_in_words'辅助函数.

为了使用FunctionalTests中的这些辅助方法,我该怎么办?

jpe*_*thy 41

包括ActionView::Helpers::DateHelper在你的模块test_helper.rbtest.rb文件.就是这样,从测试控制台:

>> 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"
Run Code Online (Sandbox Code Playgroud)