Class: Shoulda::Matchers::ActiveRecord::SerializeMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/shoulda/matchers/active_record/serialize_matcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ SerializeMatcher

Returns a new instance of SerializeMatcher.



94
95
96
97
# File 'lib/shoulda/matchers/active_record/serialize_matcher.rb', line 94

def initialize(name)
  @name = name.to_s
  @options = {}
end

Instance Method Details

#as(type) ⇒ Object



99
100
101
102
# File 'lib/shoulda/matchers/active_record/serialize_matcher.rb', line 99

def as(type)
  @options[:type] = type
  self
end

#as_instance_of(type) ⇒ Object



104
105
106
107
# File 'lib/shoulda/matchers/active_record/serialize_matcher.rb', line 104

def as_instance_of(type)
  @options[:instance_type] = type
  self
end

#descriptionObject



122
123
124
125
126
127
128
# File 'lib/shoulda/matchers/active_record/serialize_matcher.rb', line 122

def description
  description = "serialize :#{@name}"
  if @options.key?(:type)
    description += " class_name => #{@options[:type]}"
  end
  description
end

#failure_messageObject



114
115
116
# File 'lib/shoulda/matchers/active_record/serialize_matcher.rb', line 114

def failure_message
  "Expected #{expectation} (#{@missing})"
end

#failure_message_when_negatedObject



118
119
120
# File 'lib/shoulda/matchers/active_record/serialize_matcher.rb', line 118

def failure_message_when_negated
  "Did not expect #{expectation}"
end

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


109
110
111
112
# File 'lib/shoulda/matchers/active_record/serialize_matcher.rb', line 109

def matches?(subject)
  @subject = subject
  serialization_valid? && type_valid?
end