Testing Rails Helpers

Posted by Doug Fri, 31 Mar 2006 18:52:40 GMT

I’ve asked Scott four times now how write functional tests for helper methods. He’s replied the same all four times, and this time I’m going to “remember” it…

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

class HelperTest < Test::Unit::TestCase
  include ActionView::Helpers::TextHelper
  include ActionView::Helpers::TagHelper
  include ApplicationHelper
  # include whatever helpers you want to test here, sometimes you'll need
  # to include some of the Rails helpers, as I've done above.

  def test_some_helper
  end
end

By including the ApplicationHelper in your test class, you have all the methods defined on that class available as local functions. If you have helpers in other classes, you’d need to include those as well.

Posted in ,  | no comments

Comments

Comments are disabled

Copyright 2001 - 2005 by Lathi.net and Doug Alcorn

Creative Commons, Some Rights Reserved Ruby on Rails Developer Powered by Debian GNU/Linux Powered by Typo