Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

undefined local variable or method `main_app' on helper test

I got error on RSpec running my helper test on Rails Main Application (with further plugins)

 1) MenuHelper maintence menu 
   Failure/Error: before { menu = build_menu_maintence() }
 NameError:
   undefined local variable or method `main_app' for #<RSpec::Core::ExampleGroup::Nested_3::Nested_1:0x007f92f561f280>
 # ./app/helpers/menu_helper.rb:37:in `eval'
 # (eval):1:in `block in build_menu_items'
 # ./app/helpers/menu_helper.rb:37:in `eval'
 # ./app/helpers/menu_helper.rb:37:in `block in build_menu_items'
 # ./app/helpers/menu_helper.rb:23:in `each'
 # ./app/helpers/menu_helper.rb:23:in `build_menu_items'
 # ./app/helpers/menu_helper.rb:15:in `build_menu'
 # ./app/helpers/menu_helper.rb:48:in `build_menu_maintence'
 # ./spec/helpers/menu_helper_spec.rb:11:in `block (3 levels) in <top (required)>'
like image 953
Bruno Guerra Avatar asked Dec 19 '12 03:12

Bruno Guerra


1 Answers

I had success with the following in a mountable Engine:

def main_app
  Rails.application.class.routes.url_helpers
end

main_app.root_path
like image 102
wintersolutions Avatar answered Sep 19 '22 04:09

wintersolutions