# RSpec: expected: 200 got: 404 (compared using ==) — RSpec::Expectations::ExpectationNotMetError

**Code:** `RSpec::Expectations::ExpectationNotMetError: expected X got Y` · **Category:** Ruby / Rails · **Seen on:** Ruby

An RSpec `expect` assertion didn't hold: the actual value differs from what the test expected.

## 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 `let` not created before the request
- Data leaking between tests (no cleaning)
- Time/random dependent code
- Behaviour changed after refactor

## Quick fix

1. Print `response.body`/`pp record` to see the actual state
2. Use `let!` or `before` to create data
3. Use `freeze_time`/`travel_to` for time-based tests

## Detailed fix by platform

### Ruby

1. `bundle exec rspec spec/requests/users_spec.rb:12 --format documentation`

## How to diagnose

1. **Diff** — Expected vs got?
2. **Setup** — Data created?
3. **Isolation** — Clean DB?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/ruby/rspec-expectation-not-met)
