Class: Remarkable::Mongoid::Matchers::HasFieldMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/remarkable/mongoid/fields.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(field, options) ⇒ HasFieldMatcher

Returns a new instance of HasFieldMatcher.



22
23
24
25
# File 'lib/remarkable/mongoid/fields.rb', line 22

def initialize(field, options)
  self.field   = field.to_s
  self.options = { :type => Object }.merge(options)
end

Instance Attribute Details

#fieldObject

Returns the value of attribute field.



20
21
22
# File 'lib/remarkable/mongoid/fields.rb', line 20

def field
  @field
end

#optionsObject

Returns the value of attribute options.



20
21
22
# File 'lib/remarkable/mongoid/fields.rb', line 20

def options
  @options
end

Instance Method Details

#descriptionObject



32
33
34
# File 'lib/remarkable/mongoid/fields.rb', line 32

def description
  "have field #{field} #{humanized_options}"
end

#failure_message_for_shouldObject



36
37
38
# File 'lib/remarkable/mongoid/fields.rb', line 36

def failure_message_for_should
  "expected #{@subject} to have field #{field} #{humanized_options}"
end

#failure_message_for_should_notObject



40
41
42
# File 'lib/remarkable/mongoid/fields.rb', line 40

def failure_message_for_should_not
  "expected #{@subject} to not have field #{field} #{humanized_options}"
end

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
30
# File 'lib/remarkable/mongoid/fields.rb', line 27

def matches?(subject)
  @subject = subject.is_a?(Class) ? subject : subject.class
  @subject.fields.has_key?(field) && (@subject.fields[field].type == options[:type])
end