class RSpecJSONAPISerializer::Matchers::AssociationMatcher

Attributes

relationship_matcher[R]
relationship_type[R]

Public Class Methods

new(expected, relationship_matcher, relationship_type) click to toggle source
Calls superclass method
# File lib/rspec_jsonapi_serializer/matchers/association_matcher.rb, line 11
def initialize(expected, relationship_matcher, relationship_type)
  super(expected)

  @relationship_matcher = relationship_matcher
  @relationship_type    = relationship_type
end

Public Instance Methods

id_method_name(value) click to toggle source
# File lib/rspec_jsonapi_serializer/matchers/association_matcher.rb, line 30
def id_method_name(value)
  add_submatcher AssociationMatchers::IdMethodNameMatcher.new(value, expected)

  self
end
main_failure_message() click to toggle source
# File lib/rspec_jsonapi_serializer/matchers/association_matcher.rb, line 36
def main_failure_message
  [expected_message, actual_message].compact.join(", ")
end
matches?(serializer_instance) click to toggle source
# File lib/rspec_jsonapi_serializer/matchers/association_matcher.rb, line 18
def matches?(serializer_instance)
  @serializer_instance = serializer_instance

  relationship_matches? && submatchers_match?
end
serializer(value) click to toggle source
# File lib/rspec_jsonapi_serializer/matchers/association_matcher.rb, line 24
def serializer(value)
  add_submatcher AssociationMatchers::SerializerMatcher.new(value, expected)

  self
end

Private Instance Methods

actual() click to toggle source
# File lib/rspec_jsonapi_serializer/matchers/association_matcher.rb, line 60
def actual
  metadata.relationship(expected)
end
actual_message() click to toggle source
# File lib/rspec_jsonapi_serializer/matchers/association_matcher.rb, line 52
def actual_message
  actual ? "got :#{actual.relationship_type} instead" : nil
end
association_message() click to toggle source
# File lib/rspec_jsonapi_serializer/matchers/association_matcher.rb, line 56
def association_message
  relationship_matcher.to_s.split('_')
end
expected_message() click to toggle source
# File lib/rspec_jsonapi_serializer/matchers/association_matcher.rb, line 44
def expected_message
  "expected #{serializer_name} to #{association_message} #{expected}"
end
metadata() click to toggle source
# File lib/rspec_jsonapi_serializer/matchers/association_matcher.rb, line 68
def metadata
  Metadata::Relationships.new(serializer_instance)
end
relationship_matches?() click to toggle source
# File lib/rspec_jsonapi_serializer/matchers/association_matcher.rb, line 48
def relationship_matches?
  actual.present? && actual.relationship_type == relationship_type
end
relationships() click to toggle source
# File lib/rspec_jsonapi_serializer/matchers/association_matcher.rb, line 64
def relationships
  metadata.relationships
end