Class: RSpecApi::Matchers::Sort::Matcher

Inherits:
Collection::Matcher show all
Defined in:
lib/rspec-api/matchers/sort/matcher.rb

Instance Attribute Summary collapse

Attributes inherited from Response::Matcher

#response

Instance Method Summary collapse

Methods inherited from Response::Matcher

#failure_message_for_should, #failure_message_for_should_not

Constructor Details

#initialize(options = {}) ⇒ Matcher

Returns a new instance of Matcher.



9
10
11
12
# File 'lib/rspec-api/matchers/sort/matcher.rb', line 9

def initialize(options = {})
  @field = options[:by]
  @verse = options[:verse]
end

Instance Attribute Details

#fieldObject

Returns the value of attribute field.



7
8
9
# File 'lib/rspec-api/matchers/sort/matcher.rb', line 7

def field
  @field
end

#verseObject

Returns the value of attribute verse.



7
8
9
# File 'lib/rspec-api/matchers/sort/matcher.rb', line 7

def verse
  @verse
end

Instance Method Details

#descriptionObject



18
19
20
21
22
23
24
# File 'lib/rspec-api/matchers/sort/matcher.rb', line 18

def description
  if field
    %Q(be sorted by #{reverse? ? 'descending' : 'ascending'} #{field})
  else
    %Q(be sorted)
  end
end

#matches?(response) ⇒ Boolean

Returns:

  • (Boolean)


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

def matches?(response)
  super && all_objects_have_field? && has_two_objects? && is_sorted?
end