Class: Liquid::Rails::Rspec::DropMatchers::AssociationMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/liquid4-rails/rspec/drop_matchers.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options) ⇒ AssociationMatcher

Returns a new instance of AssociationMatcher.



64
65
66
67
# File 'lib/liquid4-rails/rspec/drop_matchers.rb', line 64

def initialize(name, options)
  @name    = name
  @options = options
end

Instance Attribute Details

#actualObject (readonly)

Returns the value of attribute actual.



62
63
64
# File 'lib/liquid4-rails/rspec/drop_matchers.rb', line 62

def actual
  @actual
end

#nameObject (readonly)

Returns the value of attribute name.



62
63
64
# File 'lib/liquid4-rails/rspec/drop_matchers.rb', line 62

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



62
63
64
# File 'lib/liquid4-rails/rspec/drop_matchers.rb', line 62

def options
  @options
end

Instance Method Details

#class_name(class_name) ⇒ Object



91
92
93
94
# File 'lib/liquid4-rails/rspec/drop_matchers.rb', line 91

def class_name(class_name)
  @options[:class_name] = class_name
  self
end

#descriptionObject



96
97
98
# File 'lib/liquid4-rails/rspec/drop_matchers.rb', line 96

def description
  "have association #{name}"
end

#failure_messageObject



100
101
102
# File 'lib/liquid4-rails/rspec/drop_matchers.rb', line 100

def failure_message
  %Q{expected #{actual.inspect} to define "#{name}" as :#{options[:type]} association}
end

#failure_message_when_negatedObject



104
105
106
# File 'lib/liquid4-rails/rspec/drop_matchers.rb', line 104

def failure_message_when_negated
  %Q{expected #{actual.inspect} not to define "#{name}" as :#{options[:type]} association}
end

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


69
70
71
72
73
74
75
76
77
78
79
# File 'lib/liquid4-rails/rspec/drop_matchers.rb', line 69

def matches?(actual)
  @actual = actual

  association = associations[name]
  result = association.present? && association[:type] == options[:type]
  result = result && association[:options][:scope] == options[:scope]           if options[:scope]
  result = result && association[:options][:with] == options[:with]             if options[:with]
  result = result && association[:options][:class_name] == options[:class_name] if options[:class_name]

  result
end

#scope(scope_name) ⇒ Object



86
87
88
89
# File 'lib/liquid4-rails/rspec/drop_matchers.rb', line 86

def scope(scope_name)
  @options[:scope] = scope_name
  self
end

#with(class_name) ⇒ Object



81
82
83
84
# File 'lib/liquid4-rails/rspec/drop_matchers.rb', line 81

def with(class_name)
  @options[:with] = class_name
  self
end