class RSpecJSONAPISerializer::Matchers::HaveAttributeMatchers::AsMatcher

Attributes

attribute[R]

Public Class Methods

new(attribute, expected) click to toggle source
# File lib/rspec_jsonapi_serializer/matchers/have_attribute_matchers/as_matcher.rb, line 9
def initialize(attribute, expected)
  super(expected)

  @attribute = attribute
end

Public Instance Methods

failure_message() click to toggle source
# File lib/rspec_jsonapi_serializer/matchers/have_attribute_matchers/as_matcher.rb, line 21
def failure_message
  [expected_message, actual_message].compact.join(", ")
end
matches?(serializer_instance) click to toggle source
# File lib/rspec_jsonapi_serializer/matchers/have_attribute_matchers/as_matcher.rb, line 15
def matches?(serializer_instance)
  @serializer_instance = serializer_instance

  actual == expected
end

Private Instance Methods

actual() click to toggle source
# File lib/rspec_jsonapi_serializer/matchers/have_attribute_matchers/as_matcher.rb, line 37
def actual
  attributes[attribute]
end
actual_message() click to toggle source
# File lib/rspec_jsonapi_serializer/matchers/have_attribute_matchers/as_matcher.rb, line 33
def actual_message
  "got #{actual.nil? ? 'nil' : actual} instead" if attributes.has_key?(attribute)
end
attributes() click to toggle source
# File lib/rspec_jsonapi_serializer/matchers/have_attribute_matchers/as_matcher.rb, line 41
def attributes
  serializable_hash.dig(:data, :attributes)
end
expected_message() click to toggle source
# File lib/rspec_jsonapi_serializer/matchers/have_attribute_matchers/as_matcher.rb, line 29
def expected_message
  "expected #{serializer_instance.class.name} to serialize #{attribute} as #{expected}"
end
serializable_hash() click to toggle source
# File lib/rspec_jsonapi_serializer/matchers/have_attribute_matchers/as_matcher.rb, line 45
def serializable_hash
  serializer_instance.serializable_hash
end