How do I test helpers in Rails?

aronchick picture aronchick · Jan 13, 2009 · Viewed 22.4k times · Source

I'm trying to build some unit tests for testing my Rails helpers, but I can never remember how to access them. Annoying. Suggestions?

Answer

Eugene Bolshakov picture Eugene Bolshakov · Apr 7, 2011

In rails 3 you can do this (and in fact it's what the generator creates):

require 'test_helper'

class YourHelperTest < ActionView::TestCase
  test "should work" do
    assert_equal "result", your_helper_method
  end
end

And of course the rspec variant by Matt Darby works in rails 3 too