Request spec failures (`StaticPages` 404s)
Context: My request specs failed: StaticPages GET /... returns http success
failed with Expected response to be a <2XX: success>, but was a <404: Not Found>
. This occurred for /home
, /hire_me
, /about
specs in spec/requests/static_pages_spec.rb
. The specs were using hardcoded string paths (e.g., get "/static_pages/home"
) that didn't match the actual routes defined in config/routes.rb
.
Resolution: I updated the specs to use the correct Rails path helpers (get root_path
, get hire_me_path
, get about_path
) defined by config/routes.rb
.
Learning: I learned to always use Rails path helpers (e.g., root_path
, learnings_path
, hire_me_path
) in request/system specs instead of hardcoding URL strings. This ensures tests remain accurate even if routes change and avoids simple 404 errors. Using rails routes
helps check available helpers.
Learned on: April 14, 2024
Edit