开发者

How to test custom helper in Rails?

开发者 https://www.devze.com 2022-12-21 18:34 出处:网络
How can I test a help开发者_如何学运维er method living in app/helpers/application_helper.rb? I have this code in my file test/unit/helpers/application_helper_test.rb

How can I test a help开发者_如何学运维er method living in app/helpers/application_helper.rb?

I have this code in my file test/unit/helpers/application_helper_test.rb

require 'test_helper'

class ApplicationHelperTest < ActionView::TestCase


  test "category" do
    assert categories_collection
  end

end

But I get this error "NameError: undefined local variable or method `categories_collection'"


Try this:

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

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

  def "category" do
    assert categories_collection 
  end 
end
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号