Module: RSpecApi::Matchers::Collection

Included in:
RSpecApi::Matchers
Defined in:
lib/rspec-api/matchers/collection/matcher.rb,
lib/rspec-api/matchers/collection/be_a_collection.rb

Defined Under Namespace

Classes: Matcher

Instance Method Summary collapse

Instance Method Details

#be_a_collectionObject

Passes if the object has a collection of JSON objects in the body.

Examples:

Passes if the body is a JSON array

require 'rspec-api-matchers'

body = '[{"id": 1}, {"name": "foo"}, {"name": "bar"}]'
obj = OpenStruct.new body: body

describe 'be_a_collection' do
  include RSpecApi::Matchers::Collection
  it { expect(obj).to be_a_collection }
end

# => (rspec) 1 example, 0 failures

See Also:


22
23
24
# File 'lib/rspec-api/matchers/collection/be_a_collection.rb', line 22

def be_a_collection
  RSpecApi::Matchers::Collection::Matcher.new
end