如何在Rails中测试自定义助手?

时间:2010-02-25 14:39:16

标签: ruby-on-rails ruby

如何测试app / helpers / application_helper.rb中的帮助方法?

我在我的文件test / unit / helpers / application_helper_test.rb中有这段代码

require 'test_helper'

class ApplicationHelperTest < ActionView::TestCase


  test "category" do
    assert categories_collection
  end

end

但是我得到了这个错误“NameError:undefined local variable or method`categors_collection'”

1 个答案:

答案 0 :(得分:5)

试试这个:

require File.dirname(__FILE__) + '/../test_helper'
require 'application_helper'

class ApplicationHelperTest < Test::Unit::TestCase  
  include ApplicationHelper 

  def "category" do
    assert categories_collection 
  end 
end