Rspec:在所有测试之前添加

时间:2013-08-02 22:21:15

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

基于this 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>'

0 个答案:

没有答案