辅助测试中未定义的局部变量或方法“main_app”

时间:2012-12-19 03:16:32

标签: ruby-on-rails rspec rails-engines

我在Rails主应用程序上运行我的帮助程序测试时遇到错误(带有更多插件)

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

感谢先进,

1 个答案:

答案 0 :(得分:10)

我在可安装引擎中取得了以下成功:

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

main_app.root_path