Rspec: Check if array includes object which includes property

It is also possible using the having_attributes alias:

expect(my_array).to include( an_object_having_attributes(id: 5) )

or, as in my own use case, matching the whole array:

expect(my_array).to contain_exactly(
  an_object_having_attributes(id: 5),
  an_object_having_attributes(id: 6),
  an_object_having_attributes(id: 2)
)

Leave a Comment

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