【问题标题】:Route Not Working in Rspec路由在 Rspec 中不起作用
【发布时间】:2015-06-09 20:09:48
【问题描述】:

鉴于以下轨道路线...

post '/a/link.aspx', to: 'vendor_simulator#an_action'

并且路线显示为...

Prefix Verb URI Pattern                              Controller#Action
       POST /a/link.aspx(.:format) vendor_simulator#an_action

以及以下通过测试...

it "returns http success" do
  post :an_action, return_xml, :content_type => 'application/xml'
  expect(response).to have_http_status(:success)
end

为什么下面的测试会失败...

it "returns http success" do
  post "/a/link.aspx", return_xml, :content_type => 'application/xml'
  expect(response).to have_http_status(:success)
end

带有...

  1) VendorSimulatorController POST '/a/link' returns http success
     Failure/Error: post "/a/link.aspx", return_xml, :content_type => 'application/xml'
     ActionController::UrlGenerationError:
       No route matches {:action=>"/a/link.aspx", :content_type=>"application/xml", :controller=>"vendor_simulator"}

【问题讨论】:

    标签: ruby-on-rails rspec routes


    【解决方案1】:

    看起来您有一个控制器测试(而不是集成测试)。如果是这种情况,那么第二个测试会失败,因为控制器测试绕过了路由,而是需要被告知要使用帖子(或获取、放置或删除)调用哪个操作方法,而不是获得 URL 路径。

    【讨论】:

      猜你喜欢
      • 2017-06-02
      • 2016-07-11
      • 2016-09-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多