0

看来我的 rspec 路由:controller => 'phones',:action => 'edit' 工作......它应该是 'phones/123/edit',并且根据 rspec 测试和 rake 路由是 IS。但是当我创建一个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!

什么精神分裂症?

4

1 回答 1

2

失败的原因是您缺少期望中的 id 。它应该是:

response.should redirect_to :controller => 'phones', :action => 'edit', :id=>1
于 2009-06-05T15:31:24.020 回答