Ravn::SpecHelpers::WebHelpers::
HaveJSONCollectionMatcher class
Superclass | Ravn::SpecHelpers::WebHelpers::HaveJSONBodyMatcher |
Included Modules |
|
RSpec matcher for matching Rack::Test response body from a collection endpoint
Expect that the response is a JSON Array of Objects:
expect( last_response ).to have_json_collection
Expect that there be 4 Objects in the collection:
expect( last_response ).to have_json_collection.of_length( 4 )
Expect that the collection’s objects each have an id
field with the specified IDs:
expect( last_response ).to have_json_collection.with_ids( 3, 6, 11, 14 ) # -or- with an Array of IDs (no need to splat them) ids = [3, 6, 11, 14] expect( last_response ).to have_json_collection.with_ids( ids )
Expect that the collection’s objects have the same IDs as an Array of model objects (or other objects that respond to pk):
payments = payment_fixture_factory.take( 4 ) expect( last_response ).to have_json_collection. with_same_ids_as
( payments )
Expect that the collection’s objects have the same IDs as an Array of Hashes with :id
fields:
payment_rows = payments_table.where( sender_id: 71524 ).all expect( last_response ).to have_json_collection. with_same_ids_as
( payment_rows )
Expect that the collection’s objects appear in the same order as the source Array:
payments = payment_fixture_factory.take( 4 ) expect( last_response ).to have_json_collection. with_same_ids_as
( payments ).in_same_order
Add aggregate matchers for each object in the collection:
expect( last_response ).to have_json_collection. with_same_ids_as
( payments ). and_all
( include(amount_cents: a_value > 0) )
Attributes
- collection_ids R
Sets of IDs, actual vs. expected
- expected_ids R
Sets of IDs, actual vs. expected
- extra_ids R
Sets of IDs, actual vs. expected
- missing_ids R
Sets of IDs, actual vs. expected
- order_enforced R
Sets of IDs, actual vs. expected
Public Instance Methods
Add the specified matchers
as expectations of each member of the collection.
Return an Array of text describing the expectation that the body be an Object or an Array, if a type was expected. If no type was expected, returns an empty Array.
Enforce ordering when matching IDs.
Overridden to include matching against collection IDs.
Adds an expectation that all members of the resulting collection have each of the keys in the specified fieldset
.
Set the expectation that the given expected_ids
will be present as the values of the :id
field of the collection.
Add an expectation that the collection’s objects all have an ‘:id’ field, and that the corresponding values be the same as the primary key values of the given objects
(fetched via their pk methods).
Protected Instance Methods
Returns true
if the collection contains exactly the IDs specified by
with_same_ids_as
, or if no IDs were specified.
Overridden to set the expected type to Array.