class RSpecJSONAPISerializer::Matchers::Base

Attributes

expected[R]
serializer_instance[R]
submatchers[R]

Public Class Methods

new(expected) click to toggle source
# File lib/rspec_jsonapi_serializer/matchers/base.rb, line 6
def initialize(expected)
  @expected    = expected
  @submatchers = []
end

Public Instance Methods

failure_message() click to toggle source
# File lib/rspec_jsonapi_serializer/matchers/base.rb, line 15
def failure_message
  ([main_failure_message] + submatcher_failure_messages).compact.join("\n")
end
failure_message_when_negated() click to toggle source
# File lib/rspec_jsonapi_serializer/matchers/base.rb, line 19
def failure_message_when_negated
  ([main_failure_message_when_negated] + submatcher_failure_messages_when_negated)
    .compact
    .join("\n")
end
matches?(serializer_instance) click to toggle source
# File lib/rspec_jsonapi_serializer/matchers/base.rb, line 11
def matches?(serializer_instance)
  raise NotImplementedError
end

Protected Instance Methods

add_submatcher(submatcher) click to toggle source
# File lib/rspec_jsonapi_serializer/matchers/base.rb, line 37
def add_submatcher(submatcher)
  submatchers << submatcher
end
main_failure_message() click to toggle source
# File lib/rspec_jsonapi_serializer/matchers/base.rb, line 29
def main_failure_message
  raise NotImplementedError
end
main_failure_message_when_negated() click to toggle source
# File lib/rspec_jsonapi_serializer/matchers/base.rb, line 33
def main_failure_message_when_negated
  raise NotImplementedError
end
serializable_hash() click to toggle source
# File lib/rspec_jsonapi_serializer/matchers/base.rb, line 45
def serializable_hash
  serializer_instance.serializable_hash
end
serializer_name() click to toggle source
# File lib/rspec_jsonapi_serializer/matchers/base.rb, line 49
def serializer_name
  serializer_instance.class.name
end
submatchers_match?() click to toggle source
# File lib/rspec_jsonapi_serializer/matchers/base.rb, line 41
def submatchers_match?
  submatchers.all? { |submatcher| submatcher.matches?(serializer_instance) }
end

Private Instance Methods

failing_submatchers() click to toggle source
# File lib/rspec_jsonapi_serializer/matchers/base.rb, line 63
def failing_submatchers
  @failing_submatchers ||= submatchers.select do |submatcher|
    !submatcher.matches?(serializer_instance)
  end
end
submatcher_failure_messages() click to toggle source
# File lib/rspec_jsonapi_serializer/matchers/base.rb, line 55
def submatcher_failure_messages
  failing_submatchers.map(&:failure_message)
end
submatcher_failure_messages_when_negated() click to toggle source
# File lib/rspec_jsonapi_serializer/matchers/base.rb, line 59
def submatcher_failure_messages_when_negated
  failing_submatchers.map(&:failure_message_when_negated)
end