Rspec routing specifications fail when returning param id?

My routing specifications for rspec give an incomprehensible error. In the expected v / s parameters, the real id param parameter is in the opposite position. Why and how to solve?

require "spec_helper"

describe GameController do
  describe "routing" do

    game = FactoryGirl.create(:game)

    it "routes to #show" do
      get("/game/1").should route_to("game#show", :id => 1)
    end

  end
end

This causes an error:

  1) gameController routing routes to #show
     Failure/Error: get("/game/1").should route_to("game#show", :id => 1)
       The recognized options <{"action"=>"show", "controller"=>"game", "id"=>"1"}> did not match <{"id"=>1, "controller"=>"game", "action"=>"show"}>, difference:.
       <{"id"=>1, "controller"=>"game", "action"=>"show"}> expected but was
       <{"action"=>"show", "controller"=>"game", "id"=>"1"}>.
     # ./spec/routing/game_routing_spec.rb:11:in `block (3 levels) in <top (required)>'
+4
source share
1 answer

Rails parses parameters as strings, not integers, so it is params[:id]really assigned "1"instead 1.

Try to expect the line instead:

get("/game/1").should route_to("game#show", :id => "1")
+9
source

All Articles