Class: Warp::ModelMatchers::AssociationMatcher

Inherits:
Matcher show all
Defined in:
lib/warp/model_matchers/association_matcher.rb

Instance Attribute Summary collapse

Attributes inherited from Matcher

#model_or_instance

Instance Method Summary collapse

Constructor Details

#initialize(expected_macro, key) ⇒ AssociationMatcher

Returns a new instance of AssociationMatcher.



8
9
10
11
# File 'lib/warp/model_matchers/association_matcher.rb', line 8

def initialize(expected_macro, key)
  @expected_macro = expected_macro
  @key = key
end

Instance Attribute Details

#expected_macroObject (readonly)

Returns the value of attribute expected_macro.



6
7
8
# File 'lib/warp/model_matchers/association_matcher.rb', line 6

def expected_macro
  @expected_macro
end

#keyObject (readonly)

Returns the value of attribute key.



6
7
8
# File 'lib/warp/model_matchers/association_matcher.rb', line 6

def key
  @key
end

Instance Method Details

#descriptionObject



19
20
21
# File 'lib/warp/model_matchers/association_matcher.rb', line 19

def description
  "have a #{expected_macro} association with :#{key}"
end

#failure_messageObject



23
24
25
26
27
28
29
# File 'lib/warp/model_matchers/association_matcher.rb', line 23

def failure_message
  if association
    "expected #{model_name} to #{description}, but had a #{assocation_macro} association with :#{key}"
  else
    "expected #{model_name} to #{description}"
  end
end

#failure_message_when_negatedObject



31
32
33
# File 'lib/warp/model_matchers/association_matcher.rb', line 31

def failure_message_when_negated
  "expected #{model_name} to not #{description}"
end

#matches?(model_or_instance) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
16
17
# File 'lib/warp/model_matchers/association_matcher.rb', line 13

def matches?(model_or_instance)
  @model_or_instance = model_or_instance

  association && values_match?(expected_macro, assocation_macro)
end