RSpec: expected: 200 got: 404 (compared using ==) — RSpec::Expectations::ExpectationNotMetError
An RSpec expect assertion didn't hold: the actual value differs from what the test expected.
RSpec::Expectations::ExpectationNotMetError: expected: 200 got: 404 (compared using ==)expected: 200 got: 404expected #<User> to eq #<User>Failure/Error: expect(response).to have_http_status(:ok)Failure/Error: expect(response.status).to eq(200) Meaning
Read "expected" vs "got" and the diff. Typical in request specs: wrong status because of auth/fixtures/factories, missing login_as, or changed JSON structure. Debug with puts response.body, use aggregate_failures, check let vs let! laziness, and DB cleaning/transactions.
Common causes
- Wrong status/body due to missing setup (auth, factories)
- Lazy
letnot created before the request - Data leaking between tests (no cleaning)
- Time/random dependent code
- Behaviour changed after refactor
⚡ Quick fix
- Print
response.body/pp recordto see the actual state - Use
let!orbeforeto create data - Use
freeze_time/travel_tofor time-based tests
Detailed fix by platform
Ruby
bundle exec rspec spec/requests/users_spec.rb:12 --format documentation
How to diagnose
- Diff — Expected vs got?
- Setup — Data created?
- Isolation — Clean DB?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- ActiveRecord::RecordInvalid: Validation failed Rails: ActiveRecord::RecordInvalid: Validation failed: Email can't be blank, Name is too short
- ArgumentError: missing keyword / unknown keyword Ruby: ArgumentError: missing keyword: :name / unknown keyword: :nmae
- ArgumentError: wrong number of arguments (given 1, expected 2) Ruby: ArgumentError: wrong number of arguments (given 1, expected 2..3)
Most viewed in Ruby / Rails
- ActiveRecord::PendingMigrationError Rails: ActiveRecord::PendingMigrationError — Migrations are pending. To resolve this issue, run: bin/rails db:migrate
- ActionController::InvalidAuthenticityToken Rails: ActionController::InvalidAuthenticityToken (Can't verify CSRF token authenticity)
- undefined method for nil Ruby: NoMethodError: undefined method `x' for nil (nil:NilClass)
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 5 Nov 2026