【问题标题】:undefined local variable or method `main_app' on helper test辅助测试中未定义的局部变量或方法“main_app”
【发布时间】:2012-12-19 03:16:32
【问题描述】:

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

【问题讨论】:

  • 它是什么类型的引擎?完整的,可安装的?

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


【解决方案1】:

我在可挂载引擎中取得了以下成功:

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

main_app.root_path

【讨论】:

  • 你把这个放在哪里哟?在 rails_helper 中?
  • 我也想知道这个放在哪里。
  • 认为这是在rails_helper.rbspec_helper。我想我丢失了使用它的代码。你可以随便说,引擎会尝试这样称呼它api.rubyonrails.org/classes/Rails/…
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-10-02
  • 1970-01-01
  • 2017-01-26
  • 1970-01-01
相关资源
最近更新 更多