Ruby on rails RSpec功能规格可以';无法找到Rails引擎的路径

Ruby on rails RSpec功能规格可以';无法找到Rails引擎的路径,ruby-on-rails,rspec,rspec-rails,rails-engines,Ruby On Rails,Rspec,Rspec Rails,Rails Engines,我正在使用railsv5.1.0和rspecrails3.5.2开发一个Rails引擎 我有一个简单的功能规范: require "rails_helper" module MyEngineName RSpec.feature "Some Feature", type: :feature do it "user can navigate to page and blah blah", :js do visit edit_job_path(1) # ....

我正在使用
railsv5.1.0
rspecrails3.5.2
开发一个Rails引擎

我有一个简单的功能规范:

require "rails_helper"

module MyEngineName
  RSpec.feature "Some Feature", type: :feature do
    it "user can navigate to page and blah blah", :js do
      visit edit_job_path(1)
      # .... other stuff
    end
  end
end
这就产生了错误

undefined method `edit_job_path' for #<RSpec::ExampleGroups::SomeFeature:0x007fc098a570e8>
来自rake的所有路由的列表

> rake app:routes
   ....
   ....

Routes for MyEngineName::Engine:
    root GET    /                        redirect(301, /my_engine_name/jobs)
    jobs GET    /jobs(.:format)          my_engine_name/jobs#index
         POST   /jobs(.:format)          my_engine_name/jobs#create
 new_job GET    /jobs/new(.:format)      my_engine_name/jobs#new
edit_job GET    /jobs/:id/edit(.:format) my_engine_name/jobs#edit
     job GET    /jobs/:id(.:format)      my_engine_name/jobs#show
         PATCH  /jobs/:id(.:format)      my_engine_name/jobs#update
         PUT    /jobs/:id(.:format)      my_engine_name/jobs#update
         DELETE /jobs/:id(.:format)      my_engine_name/jobs#destroy

这其中的一些东西应该会有所帮助。确保您有
MyEngineName::Engine.routes
,而不是
MyEngineName.routes

require "rails_helper"

module MyEngineName
  RSpec.feature "Some Feature", type: :feature do
    routes { MyEngineName::Engine.routes }

    it "user can navigate to page and blah blah", :js do
    # ...
或(另一种解决方案)


对于API请求规范,我尝试了两种方法,但都不起作用

routes { MyEngine::Engine.routes }

如果上述解决方案不起作用请尝试加载帮助程序URL,rspec的配置如下:

RSpec.configure do |config|
  config.include MyEngine::Engine.routes.url_helpers
end

显示你的
routes.rb
文件,至少显示前几行。@chumakoff-用它编辑了文章。谢谢@丘马科夫,你有办法吗?谢谢!第一种方法抛出一个错误-
未定义RSpec::ExampleGroups::SomeFeature:Class(NoMethodError)
,因为我认为
路由
不是一个有效的方法定义(不确定为什么?)。第二个显示了一些希望,因为它肯定能够识别
edit\u job\u path
!但是它在尝试加载该页面的资源时抛出了一个错误-
没有与[GET]匹配的路由“/assets/my_engine\u name/application-(fingerprint).js”
。这有点像,因为路线不是由路线助手定义的,对吗?我也不知道为什么它是
test
环境中的指纹资产。。。谢谢
routes { MyEngine::Engine.routes }
RSpec.configure do |config|
  config.before :each, type: :request do
    helper.class.include MyEngine::Engine.routes.url_helpers
  end
end
RSpec.configure do |config|
  config.include MyEngine::Engine.routes.url_helpers
end