I've started writing a spec for a new controller. By rights, the action for this controller should not be routeable. I have not written a route for it. Yet, somehow rspec manages to route to the action and run it.
I am very puzzled.
Here’s a spec and console output which show that this should not be routable:
it 'accepts POSTs to receiver' do
{ post: "http://api.customersure.com/webhooks/foobar/receiver" }.should route_to(controller: 'webhooks/foobar', action: 'receiver')
end
This fails, and it should fail as I haven’t added that route.
However, this controller spec passes:
describe Webhooks::FoobarController, type: :controller do
describe "POST receiver" do
it "returns 200 OK" do
post :receiver
expect(response.status).to eq(200)
end
end
end
I've quickly verified that it’s definitely routing to the #receiver action in the Foobar controller by inserting a puts
into the action. The string from that puts
appears in my console when I run the test.
So…
- Most helpful to me – can anyone explain how rspec is managing to route to this action?
- In general, how can I debug this? How can I work backwards from an action to work out what routes were followed?
Thanks!