Rspec redirect_to路由是否失败期望(或被误解?),怎么回事?

时间:2009-06-05 07:48:42

标签: ruby-on-rails ruby routing rspec actioncontroller

似乎我的rspec路线为:controller => 'phones',:action => 'edit'有效......它应该是'phones / 123 / edit',而IS则是根据rspec测试和rake路由。但是当我创建一个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?

1 个答案:

答案 0 :(得分:2)

失败的原因是你错过了期望中的id。它应该是:

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