Skip to content

ActiveAdmin, Spork, and the infamous “undefined local variable or method `view_factory’”

January 31, 2012

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
About these ads

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: