0

基于stackoverflow q,添加以下行解决了问题中解释的相同问题:

before(:each) { @routes = MyEngine::Engine.routes }

线程的最后一部分解释说,如果我添加以下内容,我不必在每个控制器文件中添加该行:

#spec/spec_helper.rb
RSpec.configure do |config|
  # other code
  config.before(:each) { @routes = MyEngine::Engine.routes }
end

但是,这最后一部分似乎不起作用。知道为什么吗?

谢谢!

更新 1 示例错误消息:

11) Core::PostsController PUT update with valid params assigns the requested post as @post
     Failure/Error: put :update, {:id => post.to_param, :post => valid_attributes}, valid_session
     ActionController::UrlGenerationError:
       No route matches {:id=>"1", :post=>{}, :controller=>"core/posts", :action=>"update"}
     # ./spec/controllers/core/posts_controller_spec.rb:115:in `block (4 levels) in <module:Core>'
4

0 回答 0