Rspec 不符合我的路线
Rspec not matching my route
我的 routes.rb
中有 post '/foo/bar', to: 'api/v1/things#bar'
。
运行 rails routes
returns
foo_bar POST /foo/bar(.:format) api/v1/things#bar
我正在尝试使用 post '/foo/bar'
对其进行测试,但我得到了
No route matches {:action=>"/foo/bar", :controller=>"api/v1/things"}
我知道这个问题很愚蠢,但我看不到它。有什么想法吗?
在控制器测试中,您应该使用实际操作名称,bar
。路由详细信息是控制器业务的none。这是一个重点测试,所以只测试控制器逻辑。
另一方面,集成测试是另一回事。他们根据定义测试整个堆栈(因此,他们也被称为 "end to end tests")。您应该能够在功能规范中 post 到 /foo/bar
,因为请求将通过路由器。
当您 运行 控制器规格时,路由不是问题。
使用:
post 'bar'
这个测试很可能有 describe API::V1:Things do
,这告诉 RSpec 使用哪个控制器。
我的 routes.rb
中有 post '/foo/bar', to: 'api/v1/things#bar'
。
运行 rails routes
returns
foo_bar POST /foo/bar(.:format) api/v1/things#bar
我正在尝试使用 post '/foo/bar'
对其进行测试,但我得到了
No route matches {:action=>"/foo/bar", :controller=>"api/v1/things"}
我知道这个问题很愚蠢,但我看不到它。有什么想法吗?
在控制器测试中,您应该使用实际操作名称,bar
。路由详细信息是控制器业务的none。这是一个重点测试,所以只测试控制器逻辑。
另一方面,集成测试是另一回事。他们根据定义测试整个堆栈(因此,他们也被称为 "end to end tests")。您应该能够在功能规范中 post 到 /foo/bar
,因为请求将通过路由器。
当您 运行 控制器规格时,路由不是问题。
使用:
post 'bar'
这个测试很可能有 describe API::V1:Things do
,这告诉 RSpec 使用哪个控制器。