【问题标题】:How to test custom helper in Rails?如何在 Rails 中测试自定义助手?
【发布时间】:2011-01-21 00:59:21
【问题描述】:

如何测试 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 `categories_collection'”

【问题讨论】:

    标签: ruby-on-rails ruby


    【解决方案1】:

    试试这个:

    require File.dirname(__FILE__) + '/../test_helper'
    require 'application_helper'
    
    class ApplicationHelperTest < Test::Unit::TestCase  
      include ApplicationHelper 
    
      def "category" do
        assert categories_collection 
      end 
    end
    

    【讨论】:

      猜你喜欢
      • 2012-03-07
      • 2010-10-01
      • 2016-10-15
      • 1970-01-01
      • 1970-01-01
      • 2012-05-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多