2

我的测试示例是:

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

这是失败消息:

UsersController routing routes to #add_role
     Failure/Error: post("/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)
4

1 回答 1

-2

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

于 2014-11-04T12:38:25.293 回答