我在routes.rb中定义了以下路由:
map.search 'fuzzyleads/search/:url', :controller => 'fuzzyleads', :action => 'search', :method => 'get'
问题是我无法通过此测试:
def test_search_route
assert_generates "fuzzyleads/search/someurl", { :controller => "fuzzyleads", :action => "search", :url => "someurl" }
end
它不喜欢url部分,我收到以下错误:
发现额外内容< {:url =>“someurl”}>而不是 < {}>
我不知道为什么,谁能看到我做错了什么?
答案 0 :(得分:0)
rake routes
的输出会帮助我们做出更好的猜测。以下是我使用rails-2.3.8进行测试的方法:
(1)在config/routes.rb
(2)创建了以下rspec测试:
it "should have valid route for fuzzyleads search" do
route_for(:controller => 'fuzzyleads', :action => 'search', :url => 'someurl').should ==
"/fuzzyleads/search/someurl"
end
但这失败了以下内容:
ActionController::RoutingError in 'FuzzyLeadsController should have valid route for fuzzyleads search'
No route matches "/fuzzyleads/search/someurl" with {:method=>:get}
If you're expecting this failure, we suggest {:get=>"/fuzzyleads/search/someurl"}.should_not be_routable
但是当我删除:method
限制时,一切都成功了。添加:method => 'get'
不足以使测试通过。当我在未满足的路线上设置条件时,我已经看到类似的失败,所以我猜你的情况会发生类似的情况。