How do I test helpers in Rails? How do I test helpers in Rails? ruby ruby

How do I test helpers in Rails?


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  endend

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


You can do the same in RSpec as:

require File.dirname(__FILE__) + '/../spec_helper'describe FoosHelper do  it "should do something" do    helper.some_helper_method.should == @something  endend


Stolen from here: http://joakimandersson.se/archives/2006/10/05/test-your-rails-helpers/

require File.dirname(__FILE__) + ‘/../test_helper’require ‘user_helper’class UserHelperTest < Test::Unit::TestCaseinclude UserHelperdef test_a_user_helper_method_hereendend

[Stolen from Matt Darby, who also wrote in this thread.] You can do the same in RSpec as:

require File.dirname(__FILE__) + '/../spec_helper'describe FoosHelper do  it "should do something" do    helper.some_helper_method.should == @something  endend