Class: Mongoid::Matchers::HaveIndexMatcher

Inherits:
Matcher
  • Object
show all
Defined in:
lib/matchers/document/have_index.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*attrs) ⇒ HaveIndexMatcher

Returns a new instance of HaveIndexMatcher.



13
14
15
# File 'lib/matchers/document/have_index.rb', line 13

def initialize *attrs
  @attrs = attrs.map(&:to_sym)
end

Instance Attribute Details

#attrsObject (readonly)

Returns the value of attribute attrs.



11
12
13
# File 'lib/matchers/document/have_index.rb', line 11

def attrs
  @attrs
end

#klassObject (readonly)

Returns the value of attribute klass.



11
12
13
# File 'lib/matchers/document/have_index.rb', line 11

def klass
  @klass
end

Instance Method Details

#descriptionObject



30
31
32
# File 'lib/matchers/document/have_index.rb', line 30

def description
  "have an index for #{attrs.inspect}"
end

#failure_messageObject



22
23
24
# File 'lib/matchers/document/have_index.rb', line 22

def failure_message
  "#{klass} to #{description}, but only found indexes #{indexes.inspect}"
end

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
20
# File 'lib/matchers/document/have_index.rb', line 17

def matches? subject
  @klass = class_of subject
  index_options.any? { |idx, _| idx.keys == attrs }
end

#negative_failure_messageObject



26
27
28
# File 'lib/matchers/document/have_index.rb', line 26

def negative_failure_message
  "#{klass} to not #{description}, but found an index for #{attrs.inspect}"
end