Test that a hash contains a partial hash with RSpec

To test whether a hash includes an expected sub-hash:

expect(user.attributes).to match(hash_including('name' => 'Bruce Wayne'))
expect(User).to receive(:create!).with(hash_including('name' => 'Bruce Wayne'))
Henning Koch About 13 years ago