2009-06-05 39 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