2012-04-26 37 views
0

我application_helper.rb文件:如何在Rails 3的我的application_helper文件中测试助手方法?

module ApplicationHelper 
    def option_text(option_id) 
    Option.find(option_id).title 
    end 
end 

我在哪里,在测试这种方法?当我创建脚手架时,Rails会生成助手测试文件,但是我在哪里为此方法进行了测试,因为它在Application Helper中?我曾尝试将测试放置在使用脚手架生成的视图帮助程序测试文件之一中,但无法找到上述方法。

回答

1

添加一个文件夹下所谓的“帮手”测试/单元,然后建立这样你的助手测试文件:

# application_helper_test.rb 
require File.dirname(__FILE__) + '/../../test_helper' 
require 'action_view/test_case' 

class ApplicationHelperTest < ActionView::TestCase 
    test 'option_text' do 
    assert true 
    end 
end 

上有测试佣工这里其他一些有用的提示: http://technicalpickles.com/posts/helper-testing-using-actionview-testcase/

相关问题