2009-06-05 43 views
0

看起來我的rspec路線爲:controller =>'phones',:action =>'edit'works ...它應該是'phones/123/edit',並且根據rspec測試和耙路由。但是當我創建redirect_to期望時,期望失敗。Rspec redirect_to路由失敗(或錯誤分析?),怎麼回事?

下面是該URL路由測試:

it "maps #edit" do 
     route_for(:controller => "phones", :action => "edit", :id => "1").should == "/phones/1/edit" 
    end #THIS TEST PASSES 

下面是失敗的期望:

put :update, :id => "1", :phone => {} 
    response.should redirect_to :controller => 'phones', :action => 'edit' 

這是我在測試中得到的消息:

expected redirect to {:controller=>"phones", :action=>"edit"}, 
got redirect to "http://test.host/phones/1089/edit" # BUT THIS THE URL I WAS EXPECTING! 

什麼是schiznits?

回答

2

這是失敗的原因是,你錯過了期望中的id。它應該是:

response.should redirect_to :controller => 'phones', :action => 'edit', :id=>1 
+0

足夠關閉......我artually最後不得不使用這樣的mock_phone.id: response.should redirect_to的:控制器=> '手機',:動作=> '編輯' ,:id => wock_phone.id 謝謝佩爾!順便說一下,我在哪裏見過你?我感覺我在Github或其他論壇上看到過你。 – btelles 2009-06-05 16:18:25