每天一剂Rails良药之Write Tests for Your Helpers

今天我们看看怎么测试我们的helper方法:
require File.dirname(__FILE__) + '/../test_helper'

class HelperTest < Test::Unit::TestCase
  include ActionView::Helpers::UrlHelper
  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

通过include ApplicationHelper,则该类里面定义的所有方法都可以作为本地方法得到
如果想测试其它类里面的helper方法,我们只需要将该类include即可

你可能感兴趣的:(Rails)