This example is a little bit misleading because theres not necessarily a method called items on cart, e.g. there's no class definition. See the [feature](/rspec/rspec-collection_matchers/blob/4edb4f2b2aadb28e9151b908757f8a20b50b69cb/features/have.feature) and maybe use one of the examples from that.