testing helpers with 'haml_tag'
-
06-09-2019 - |
Question
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!
Solution
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.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow