Class: Mongoid::Matchers::Document::DocumentMatcher

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mod) ⇒ DocumentMatcher

Returns a new instance of DocumentMatcher.



36
37
38
# File 'lib/matchers/document/document.rb', line 36

def initialize mod
  @mod = mod
end

Instance Attribute Details

#modObject (readonly)

Returns the value of attribute mod.



34
35
36
# File 'lib/matchers/document/document.rb', line 34

def mod
  @mod
end

Instance Method Details

#descriptionObject



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/matchers/document/document.rb', line 52

def description
  msg = case
        when mod == DOCUMENT   then ''
        when mod == PARANOIA   then 'paranoid '
        when mod == VERSIONING then 'versioned '
        when mod == TIMESTAMPS then 'timestamped '
        else raise "Unknow Mongoid module #{mod}"
        end

  "be a #{msg}Mongoid document"
end

#failure_messageObject



44
45
46
# File 'lib/matchers/document/document.rb', line 44

def failure_message
  "Expected #{inspect} to #{description}"
end

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/matchers/document/document.rb', line 40

def matches? subject
  class_of(subject).included_modules.include? mod
end

#negative_failure_messageObject



48
49
50
# File 'lib/matchers/document/document.rb', line 48

def negative_failure_message
  "Expected not to #{description}"
end