繁体   English   中英

使用RSpec测试父Rails应用程序时引擎的访问路径帮助器

[英]access path helper for an engine when testing parent Rails app with RSpec

我有一个Rails引擎和一个包含它的Rails 4应用程序。 我想在父级Rails应用程序中编写RSpec测试,以验证Rails应用程序的控制器之一重定向到引擎内部的路径。 当我为Rails应用程序运行rake routes ,我会看到所需的引擎路径,并对其进行了命名。 我可以通过说my_engine.my_engine_path在我的Rails应用程序的视图内引用该路径。 但是,在我的Rails应用程序的RSpec控制器测试中, my_engine似乎不是问题。 我不想在我的应用程序的spec_helper.rb执行以下操作,因为这似乎spec_helper.rb我的应用程序的路由与引擎的连接spec_helper.rb

config.include Module.new {
  def self.included base
    base.routes { MyEngine::Engine.routes }
  end
}, type: :controller

当我执行以下操作时,会得到undefined local variable or method 'my_engine'

expect(response).to redirect_to(my_engine.my_engine_path(some_route_param))

我的问题出在我的路线上。 我使用的是path参数而不是id因为控制器处理文件系统上的文件,而不是数据库记录。 我有resources :my_controller而不是resources :my_controller, param: :path, constraints: {path: /.*/} 所以在我的应用程序的RSpec控制器测试中没有对my_engine. expect(response).to redirect_to(my_engine_path(some_route_param)) my_engine. 需要前缀。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM