RSpec partial match against a nested hash

You are able to use and nest the hash_including method for these matchers.

Using your example, you can rewrite your test code to look like:

expect(response_json).to include(hash_including({
  employee: hash_including(jobs_count: 0)
}))

(or if response_json is a single object, replace include with match)

This will also work when dealing with .with constraints, for example:

expect(object).to receive(:method).with(hash_including(some: 'value'))

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)