ActiveAdmin, Spork, and the infamous “undefined local variable or method `view_factory’”
If you are using ActiveAdmin and you are also using Spork as part of your testing suite you are probably extremely frustrated with an error that looks something like this:
ActionView::Template::Error: undefined local variable or method `view_factory' for #<#Class:0x000001070ccf80:0x000001070c7648>
This issue has been queued and is discussed further here:
https://github.com/gregbell/active_admin/issues/918
Your solution is simple. Just add the following to your test/test_helper.rb:
Spork.each_run do
ActionView::Template.register_template_handler :arb, lambda { |template|
"self.class.send :include, Arbre::Builder; @_helpers = self; self.extend ActiveAdmin::ViewHelpers; @__current_dom_element__ = Arbre::Context.new(assigns, self); begin; #{template.source}; end; current_dom_context"
}
end
Leave a Comment