Route Not Working in Rspec

236 Views Asked by At

Given the follow rails route ...

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

and the route shows as ...

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

And the following passing test ...

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

Why does the following test fail ...

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

with a ...

  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"}
1

There are 1 best solutions below

0
On BEST ANSWER

It looks like you have a controller test (as opposed to an integration test). If that's the case then the second one fails because controller tests bypass the routing and instead need to be told which action method to call with a post (or get or put or delete) instead of being given a URL path.