Class: DataMapperMatchers::HasMany

Inherits:
Object
  • Object
show all
Defined in:
lib/spec/matchers/dm/has_many.rb

Instance Method Summary collapse

Constructor Details

#initialize(name, options) ⇒ HasMany

Returns a new instance of HasMany.



11
12
13
14
# File 'lib/spec/matchers/dm/has_many.rb', line 11

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

Instance Method Details

#descriptionObject



24
25
26
# File 'lib/spec/matchers/dm/has_many.rb', line 24

def description
  "has many"
end

#failure_messageObject



28
29
30
31
32
# File 'lib/spec/matchers/dm/has_many.rb', line 28

def failure_message
  # TODO: filter just has many relationships
  properties = @model.properties.entries.map { |property| property.name }.inspect
  "expected to has many #@name, but has just the following properties: #{properties}"
end

#matches?(model) ⇒ Boolean

args<Model>: Category

Returns:

  • (Boolean)


17
18
19
20
21
22
# File 'lib/spec/matchers/dm/has_many.rb', line 17

def matches?(model)
  @model = model
  relationship = @model.relationships[@name]
  return false unless relationship
  relationship.parent_model == @model && @options.all? { |key, value| relationship.options[key] == value }
end

#negative_failure_messageObject



34
35
36
# File 'lib/spec/matchers/dm/has_many.rb', line 34

def negative_failure_message
  "expected to not has many #@name, but had"
end