Module: RSpec::Matchers
- Defined in:
- lib/rspec/collection_matchers/matchers.rb
Instance Method Summary collapse
-
#have(n) ⇒ Object
(also: #have_exactly, #a_collection_having)
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.
-
#have_at_least(n) ⇒ Object
Exactly like have() with >=.
-
#have_at_most(n) ⇒ Object
Exactly like have() with <=.
Instance Method Details
#have(n) ⇒ Object Also known as: have_exactly, a_collection_having
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 expectations about their lengths.
33 34 35 |
# File 'lib/rspec/collection_matchers/matchers.rb', line 33 def have(n) RSpec::CollectionMatchers::Have.new(n) end |
#have_at_least(n) ⇒ Object
Exactly like have() with >=.
### Warning:
‘expect(..).not_to have_at_least` is not supported
47 48 49 |
# File 'lib/rspec/collection_matchers/matchers.rb', line 47 def have_at_least(n) RSpec::CollectionMatchers::Have.new(n, :at_least) end |
#have_at_most(n) ⇒ Object
Exactly like have() with <=.
### Warning:
‘expect(..).not_to have_at_most` is not supported
59 60 61 |
# File 'lib/rspec/collection_matchers/matchers.rb', line 59 def have_at_most(n) RSpec::CollectionMatchers::Have.new(n, :at_most) end |