class Ndd::RSpec::Matchers::BeReverseSortedBy


Implements {#be_reverse_sorted_by}.

Public Class Methods

new(attribute) click to toggle source

@param attribute [Symbol] the attribute or the method to sort with.

# File lib/ndd/rspec/matchers/be_reverse_sorted_by.rb, line 29
def initialize(attribute)
  @attribute = attribute
end

Public Instance Methods

description() click to toggle source

@return [String] a description of this matcher.

# File lib/ndd/rspec/matchers/be_reverse_sorted_by.rb, line 44
def description
  "be sorted in reverse order by '#{@attribute}'"
end
failure_message() click to toggle source

@return [String] details about the failure of this matcher.

# File lib/ndd/rspec/matchers/be_reverse_sorted_by.rb, line 49
def failure_message
  message = ''
  message << "expected '#{@actual.inspect}'to be sorted in reverse order by '#{@attribute}' but\n"
  message << "  expected attributes: #{@expected_attributes.inspect}\n"
  message << "  actual attributes: #{@actual_attributes.inspect}"
  message
end
matches?(actual) click to toggle source

@param actual [Object] the object being tested. @return [Boolean] true if the object is reverse sorted according to the given attribute, false otherwise.

# File lib/ndd/rspec/matchers/be_reverse_sorted_by.rb, line 35
def matches?(actual)
  @actual = actual
  attributes = actual.collect { |e| e.send(@attribute) }
  @actual_attributes = attributes
  @expected_attributes = attributes.sort.reverse
  @expected_attributes == @actual_attributes
end