Class: RSpecJSONAPISerializer::Matchers::AssociationMatcher

Inherits:
Base
  • Object
show all
Defined in:
lib/rspec_jsonapi_serializer/matchers/association_matcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(expected, relationship_matcher, relationship_type) ⇒ AssociationMatcher

Returns a new instance of AssociationMatcher.



12
13
14
15
16
17
# File 'lib/rspec_jsonapi_serializer/matchers/association_matcher.rb', line 12

def initialize(expected, relationship_matcher, relationship_type)
  super(expected)

  @relationship_matcher = relationship_matcher
  @relationship_type    = relationship_type
end

Instance Method Details

#descriptionObject



43
44
45
46
47
# File 'lib/rspec_jsonapi_serializer/matchers/association_matcher.rb', line 43

def description
  description = "#{association_message} #{expected}"

  [description, submatchers.map(&:description)].flatten.join(' ')
end

#failure_messageObject



49
50
51
# File 'lib/rspec_jsonapi_serializer/matchers/association_matcher.rb', line 49

def failure_message
  "Expected #{expectation}"
end

#failure_message_when_negatedObject



53
54
55
# File 'lib/rspec_jsonapi_serializer/matchers/association_matcher.rb', line 53

def failure_message_when_negated
  "Did not expect #{expectation}"
end

#id_method_name(value) ⇒ Object



31
32
33
34
35
# File 'lib/rspec_jsonapi_serializer/matchers/association_matcher.rb', line 31

def id_method_name(value)
  add_submatcher AssociationMatchers::IdMethodNameMatcher.new(value, expected)

  self
end

#matches?(serializer_instance) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
23
# File 'lib/rspec_jsonapi_serializer/matchers/association_matcher.rb', line 19

def matches?(serializer_instance)
  @serializer_instance = serializer_instance

  relationship_matches? && submatchers_match?
end

#object_method_name(value) ⇒ Object



37
38
39
40
41
# File 'lib/rspec_jsonapi_serializer/matchers/association_matcher.rb', line 37

def object_method_name(value)
  add_submatcher AssociationMatchers::ObjectMethodNameMatcher.new(value, expected)

  self
end

#serializer(value) ⇒ Object



25
26
27
28
29
# File 'lib/rspec_jsonapi_serializer/matchers/association_matcher.rb', line 25

def serializer(value)
  add_submatcher AssociationMatchers::SerializerMatcher.new(value, expected)

  self
end