Ad

How Do I Test Helpers In Rails?

- 1 answer

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

Ad

Answer

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

Ad
source: stackoverflow.com
Ad