2013-10-07 10 views
4

rspec에 대한 내 라우팅 사양이 명확하지 않은 오류를 반환합니다. 예상 매개 변수 v/s에서 실제 매개 변수 id 매개 변수는 반전 된 위치에 있습니다. 왜, 어떻게 해결해야합니까? 그래서 params[:id] 정말 "1" 대신 1 할당되고Rspec 라우팅 사양에서 param id가 반대로 실패합니다.

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)>' 

답변

9

레일 문자열이 아닌 정수로 매개 변수를 구문 분석 :

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 

이 오류가 발생합니다.

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

예, 작은 일 하나 간과 할 수 있지만이 완전히 그것을 해결

대신 문자열을 기대하십시오! 고맙습니다 – Rubytastic