Rails RSpec 路由:在 :except do NOT route 中测试操作 [英] Rails RSpec Routing: Testing actions in :except do NOT route
问题描述
相当简单的问题(我曾想过),但我遇到了一些问题:
在 Rails 3.1.0.rc6/RSpec 2.6.0 中,我试图测试我的产品"资源的路由,路由如下:
resources :products, :except =>[:编辑,:更新]
有效操作的路由有效,但我想确保编辑和更新路由不可调用.这是我正在尝试的:
它不路由到#edit"做lambda { get("/products/1/edit") }.should raise_error结尾
<块引用>
失败/错误:lambda { get("/products/1/edit") }.should raise_error预期异常,但没有提出任何问题# ./spec/routing/products_routing_spec.rb:11:in `block (3 级)在'
...然而,当我跑步时
它不路由到#edit"做get("/products/1/edit").should_not route_to("products#edit", :id => "1")结尾
我明白
<块引用>失败/错误:get("/products/1/edit").should_notroute_to("products#edit", :id => "1")ActionController::RoutingError:没有路由匹配/products/1/edit"
知道这里发生了什么吗?我猜这应该很简单,但我似乎无法弄清楚.
我不知道为什么 lambda 会失败,但我不认为 rspec-rails dsl 打算这样使用.你有没有尝试过这样的事情?
{ :get =>"/products/1/edit" }.should_not be_routable
http://relishapp.com/rspec/rspec-rails/docs/routing-specs/be-routable-matcher
所以你不能指定它不路由到什么,但你可以指定它不路由.
Fairly simple problem (I'd have thought), but I'm having some issues:
In Rails 3.1.0.rc6/RSpec 2.6.0, I'm trying to test the routing of my 'products' resource, routed like this:
resources :products, :except => [:edit, :update]
The routing for the valid actions works, but I want to ensure that the edit and update routes are not callable. Here's what I'm trying:
it "does not route to #edit" do
lambda { get("/products/1/edit") }.should raise_error
end
Failure/Error: lambda { get("/products/1/edit") }.should raise_error expected Exception but nothing was raised # ./spec/routing/products_routing_spec.rb:11:in `block (3 levels) in '
...And yet, when I run
it "does not route to #edit" do
get("/products/1/edit").should_not route_to("products#edit", :id => "1")
end
I get
Failure/Error: get("/products/1/edit").should_not route_to("products#edit", :id => "1") ActionController::RoutingError: No route matches "/products/1/edit"
Any idea what's going on here? I'm guessing this should be pretty simple, but I can't seem to figure it out.
I don't know why the lambda would fail, but I don't think the rspec-rails dsl is intended to be used like that. Have you tried something like this?
{ :get => "/products/1/edit" }.should_not be_routable
http://relishapp.com/rspec/rspec-rails/docs/routing-specs/be-routable-matcher
So you can't specify what it doesn't route to, but you can specify that it doesn't get routed.
这篇关于Rails RSpec 路由:在 :except do NOT route 中测试操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!