【发布时间】:2017-04-28 16:26:58
【问题描述】:
将 Rails 4.2.8 升级到 5.0 后,我的所有路由规范都失败并显示相同的错误消息:
1) UsersController routing routes to SHOW
Failure/Error: expect(get: '/users/joe-smith').to route_to('users#show', id: 'joe-smith')
The recognized options <{"path"=>"users/joe-smith", "controller"=>"users", "action"=>"show", "id"=>"joe-smith"}> did not match <{"id"=>"joe-smith", "controller"=>"users", "action"=>"show"}>, difference:.
--- expected
+++ actual
@@ -1 +1 @@
-{"id"=>"joe-smith", "controller"=>"users", "action"=>"show"}
+{"path"=>"users/joe-smith", "controller"=>"users", "action"=>"show", "id"=>"joe-smith"}
# ./spec/routing/users_controller_routing_spec.rb:10:in `block (3 levels) in <top (required)>'
Finished in 0.05154 seconds (files took 6.86 seconds to load)
1 example, 1 failure
Failed examples:
rspec ./spec/routing/users_controller_routing_spec.rb:9 # UsersController routing routes to SHOW
规格:
it 'routes to SHOW' do
expect(get: '/users/joe-smith').to route_to('users#show', id: 'joe-smith')
end
有人知道为什么会这样吗?我没有在 Rails 5 CHANGELOG 中看到任何内容。
【问题讨论】:
-
除了复制路径之外,还有什么优雅的解决方法?
-
首先使用
.to route_to规范是毫无价值的。无论如何,您应该至少有一个功能或请求规范应该涵盖这一点。 -
至于为什么 - 它实际上可能不是 Rails 中已发布的更改。这可能是 RSpec-Rails 中的回归。
标签: ruby-on-rails ruby testing rspec ruby-on-rails-5