Rspec redirect_to 路由未达到预期(或错误解析?),这是怎么回事?
这似乎是我的 rspec 路线:controller => '电话', :action => “编辑”有效...它应该是“phones/123/edit”,并且根据 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?
It seems my rspec route for :controller => 'phones', :action => 'edit' works...it should be 'phones/123/edit', and IS according to rspec tests and rake routes. But when I create a redirect_to expectation, the expectation fails.
Here's the routes test for the url:
it "maps #edit" do
route_for(:controller => "phones", :action => "edit", :id => "1").should == "/phones/1/edit"
end #THIS TEST PASSES
Here's the expectation that fails:
put :update, :id => "1", :phone => {}
response.should redirect_to :controller => 'phones', :action => 'edit'
And this is the message I get in the tests:
expected redirect to {:controller=>"phones", :action=>"edit"},
got redirect to "http://test.host/phones/1089/edit" # BUT THIS THE URL I WAS EXPECTING!
What the schiznits?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
失败的原因是您缺少期望中的 id。 它应该是:
The reason this is failing is that you are missing the id in your expectation. It should be: