这是我的路线
match "/:type/:brand/:model/:plate" => "site/vehicles#show",
:constraints => {:plate => /[a-z]{3}\d{4}/}, :as => :vehicle
通过路线测试
# the route test passess
it "routes to #show" do
{:get => '/carro/volksvagen/gol-2-0/abc1234'}.should route_to(
"site/vehicles#show",
:type => "carro",
:brand => "volksvagen",
:model => "gol-2-0",
:plate => "abc1234"
)
end
但是在升级了轨道(3.2.0 => 3.2.8)并且还更新了行程(1.0.0 => 1.0.4)之后,进行了以下的CONTROLLER测试(恕我直言,不应该检查路线,这显然是没有,回到轨道3.2.0)开始失败。
describe "#show" do
it "should be success" do
get :show, :plate => @vehicle.plate
response.should be_success
end
end
提出
Site::VehiclesController#show should be success
ActionController::RoutingError:
No route matches {:plate=>"ABC1672", :controller=>"site/vehicles",
:action=>"show"}
即使我完成了所有的路线变量
describe "#show" do
it "should be success" do
get :show, :plate => @vehicle.plate, :model => 'model',
:type => 'type', :brand => 'brand'
response.should be_success
end
end
我明白了:
# No route matches {:plate=>"ABC1586", :model=>"model", :type=>"type",
:brand=>"brand", :controller=>"site/vehicles", :action=>"show"}
应用程序仍然有效,但我不知道它何时停止,因为我的测试失败了。
有人解决了/有类似的问题吗?
我知道'不升级rails'可以避免出现这种错误,正如类似问题所示,但我不认为这是一个解决方案。
Routing error when updating to Rails 3.2.6 or Rspec 2.11.0
提前谢谢。
vehicle /:type/:brand/:model/:plate(.:format) site/vehicles#show {:plate=>/[a-z]{3}\d{4}/}
答案 0 :(得分:1)
我认为您的问题是正则表达式与测试数据不匹配。在您的错误消息中,我看到:
No route matches {:plate=>"ABC1586", :model=>"model", :type=>"type",
:brand=>"brand", :controller=>"site/vehicles", :action=>"show"}
但该路线有以下正则表示板块:
:plate => /[a-z]{3}\d{4}/
这需要所有小写字母;大写字母不匹配。因此,您需要修复测试数据,或修复路线中的正则表达式。