Background
I am trying to port an old ActionDispatch::IntegrationTest test to rspec.
This test is currently passing:
require 'test_helper'
class HeartbeatControllerTest < ActionDispatch::IntegrationTest
test "heartbeat" do
get "/heartbeat"
assert_response :success
end
end
Controller
I have a HeartbeatController which returns a 200:
class HeartbeatController < ApplicationController
def show
render(json: { 'status': 'ok' })
end
end
It works fine with curl.
Route
rake routes shows the route:
Prefix Verb URI Pattern Controller#Action
heartbeat GET /heartbeat(.:format) heartbeat#show
Spec
My test is pretty straightforward:
require 'rails_helper'
describe HeartbeatController do
it 'succeeds' do
get '/heartbeat'
expect(response).to be_success
end
end
But when I run it
Failures:
1) HeartbeatController succeeds
Failure/Error: get '/heartbeat'
ActionController::UrlGenerationError:
No route matches {:action=>"/heartbeat", :controller=>"heartbeat"}
# ./spec/controllers/heartbeat_controller_spec.rb:5:in `block (2 levels) in <top (required)>'
Finished in 0.00718 seconds (files took 1.11 seconds to load)
1 example, 1 failure
Failed examples:
rspec ./spec/controllers/heartbeat_controller_spec.rb:4 # HeartbeatController succeeds
Questions
- Why is this test failing?
- What did I do wrong?
- How could I debug this further if Stack Overflow didn't exist?