Module: RSpecApi::Matchers::Filter

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

Defined Under Namespace

Classes: Matcher

Instance Method Summary collapse

Instance Method Details

#be_filtered(options = {}) ⇒ Object

Passes if the object has a non-empty filtered JSON collection in the body.

Examples:

Passes if the body only contains objects with ID > 1

require 'rspec-api-matchers'

body = '[{"id": 2}, {"id": 3}]'
obj = OpenStruct.new body: body

describe 'be_filtered' do
  include RSpecApi::Matchers::Filter
  it { expect(obj).to be_filtered by: :id, value: 1, compare_with: :> }
end

# => (rspec) 1 example, 0 failures

Parameters:

  • options (Hash) (defaults to: {})

    how the body is expected to be filtered.

Options Hash (options):

  • :by (Symbol or String)

    The JSON key to be filtered by

  • :value (Object)

    The expected value for the field

  • :compare_with (Proc or Symbol) — default: :==

    The operator used to compare the expected value with the values in the collection

See Also:


28
29
30
# File 'lib/rspec-api/matchers/filter/be_filtered.rb', line 28

def be_filtered(options = {})
  RSpecApi::Matchers::Filter::Matcher.new options
end