Testing view helpers

Viewed 799

I'm currently working on a Rails plugin used for generating iPhone specific HTML meta-tags. I'm trying to use ActionView::TestCase for unit tests but keep getting the same error. See file contents and error below. Any ideas or help would be much appreciated.

test_helper.rb

require 'rubygems'
require 'test/unit'
require 'active_support'
require 'action_view'
require File.join(File.dirname(__FILE__), '..', 'lib', 'iphone_helper')

iphone_test_helper.rb

require 'test_helper'

class IphoneHelperTest < ActionView::TestCase
  test 'br' do
    tag = tag('br')
    assert_tag_in tag, '<br />'
  end
end

error

RuntimeError: In order to use #url_for, you must include routing helpers explicitly. For instance, `include Rails.application.routes.url_helpers
3 Answers

Did you try to include the respective Module in an old-fashioned way?:

include ActionDispatch::Routing::RouteSet

If a NameError is raised telling you that ActionDispatch is unknown you might have to require 'action_dispatch'.

Maybe a stupid question, but is the fact that the class name and the file name don't match possibly a problem (IphoneHelperTest vs. iphone_test_helper.rb)? Sometimes that leads to classes not being loaded.

Related