Rspec redirect_to 路由未达到预期(或错误解析?),这是怎么回事?

发布于 2024-07-22 21:16:52 字数 757 浏览 7 评论 0原文

这似乎是我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

开始看清了 2024-07-29 21:16:53

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

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

The reason this is failing is that you are missing the id in your expectation. It should be:

response.should redirect_to :controller => 'phones', :action => 'edit', :id=>1
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文