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

Methods inherited from Warp::Matcher

#description_of, #failure_message_for_should, #failure_message_for_should_not, #values_match?

Constructor Details

#initialize(expected_macro, key) ⇒ AssociationMatcher

Returns a new instance of AssociationMatcher.



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

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.



4
5
6
# File 'lib/warp/model_matchers/association_matcher.rb', line 4

def expected_macro
  @expected_macro
end

#keyObject (readonly)

Returns the value of attribute key.



4
5
6
# File 'lib/warp/model_matchers/association_matcher.rb', line 4

def key
  @key
end

Instance Method Details

#descriptionObject



17
18
19
# File 'lib/warp/model_matchers/association_matcher.rb', line 17

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

#failure_messageObject



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

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



29
30
31
# File 'lib/warp/model_matchers/association_matcher.rb', line 29

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

#matches?(model_or_instance) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
14
15
# File 'lib/warp/model_matchers/association_matcher.rb', line 11

def matches?(model_or_instance)
  @model_or_instance = model_or_instance

  association && values_match?(expected_macro, assocation_macro)
end