have(n) public

Passes if receiver is a collection with the submitted number of items OR if the receiver OWNS a collection with the submitted number of items.

If the receiver OWNS the collection, you must use the name of the collection. So if a Team instance has a collection named #players, you must use that name to set the expectation.

If the receiver IS the collection, you can use any name you like for named_collection. We’d recommend using either "elements", "members", or "items" as these are all standard ways of describing the things IN a collection.

This also works for Strings, letting you set an expectation about its length


  # Passes if team.players.size == 11
  team.should have(11).players

  # Passes if [1,2,3].length == 3
  [1,2,3].should have(3).items #"items" is pure sugar

  # Passes if "this string".length == 11
  "this string".should have(11).characters #"characters" is pure sugar
Show source
Register or log in to add new notes.