views:

288

answers:

2
module FooHelper
  def foo
    haml_tag(:div) do
      haml_content("bar")
    end
  end
end

When I test this I get:

NoMethodError: undefined method `haml_tag'

This code is perfectly valid and works in a development/production environment.

It's something to do with having the haml helpers properly loaded in the test environment.

Thanks!

A: 

It looks like the Rails test scaffold isn't including Haml::Helpers in its context. If you're using Test::Unit, you can probably just include it yourself in the test class. You'll also want to run Haml::Helpers#init_haml_helpers in the test setup so that all the Haml stuff is properly initialized.

nex3
This just gives me another error:NoMethodError: You have a nil object when you didn't expect it!The error occurred while evaluating nil.html? haml (2.0.9) lib/haml/helpers.rb:349:in `haml_tag'
crankharder
Are you sure you called `init_haml_helpers` correctly?
nex3