xaver23
xaver23

Reputation: 1321

How to test custom helper in Rails?

How can I test a helper 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'"

Upvotes: 3

Views: 543

Answers (1)

John Topley
John Topley

Reputation: 115422

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

Upvotes: 5

Related Questions