2012-07-07 49 views
2

我测试的例子是:路由规格失败,因为哈希存储不同

it "routes to #add_role" do 
    post("https://stackoverflow.com/users/1/add_role").should route_to("users#add_role",id: 1) 
end 

这里是失败消息:

UsersController routing routes to #add_role 
    Failure/Error: post("https://stackoverflow.com/users/1/add_role").should route_to("users#add_role",id: 1) 
     The recognized options <{"controller"=>"users", "action"=>"add_role", "id"=>"1"}> did not match <{"id"=>1, "controller"=>"users", "action"=>"add_role"}>, difference: <{"id"=>1}>. 
     <{"id"=>1, "controller"=>"users", "action"=>"add_role"}> expected but was 
     <{"controller"=>"users", "action"=>"add_role", "id"=>"1"}>. 

我的环境:

  • 红宝石1.9.3 -p194
  • 导轨3.2.6
  • Rspec(2.10.0)
+7

参数值作为字符串传递。使用'route_to(“users#add_role”,id:“1”)' – 2012-07-07 12:55:17

+0

感谢@injekt它现在正在工作。 – Amer 2012-07-07 13:03:58

回答

-2

您需要将route_to中的id设置为字符串。 Rails不会将类型转换为数字,因为它不会对类型进行任何假设