Module: RSpecApi::Matchers::Sort

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

Defined Under Namespace

Classes: Matcher

Instance Method Summary collapse

Instance Method Details

#be_sorted(options = {}) ⇒ Object

Passes if the response body is a non-empty sorted JSON collection

For more examples check be_sorted_spec.rb.

Examples:


# Passes if the body is sorted by descending IDs
body = '[{"id": 3}, {"id": 2}, {"id": 1}]'
expect(OpenStruct.new body: body).to be_sorted(by: :id, verse: :desc)


15
16
17
# File 'lib/rspec-api/matchers/sort/be_sorted.rb', line 15

def be_sorted(options = {})
  RSpecApi::Matchers::Sort::Matcher.new options
end