undefined local variable or method `main_app' on helper test

回眸只為那壹抹淺笑 提交于 2019-12-10 13:07:27

问题


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)>'

Thanks for advanced,


回答1:


I had success with the following in a mountable Engine:

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

main_app.root_path


来源:https://stackoverflow.com/questions/13944991/undefined-local-variable-or-method-main-app-on-helper-test

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!