Class: Shoulda::Matchers::ActiveRecord::SerializeMatcher
- Inherits:
-
Object
- Object
- Shoulda::Matchers::ActiveRecord::SerializeMatcher
- Defined in:
- lib/shoulda/matchers/active_record/serialize_matcher.rb
Instance Method Summary collapse
- #as(type) ⇒ Object
- #as_instance_of(type) ⇒ Object
- #description ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(name) ⇒ SerializeMatcher
constructor
A new instance of SerializeMatcher.
- #matches?(subject) ⇒ Boolean
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 |
#description ⇒ Object
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_message ⇒ Object
114 115 116 |
# File 'lib/shoulda/matchers/active_record/serialize_matcher.rb', line 114 def "Expected #{expectation} (#{@missing})" end |
#failure_message_when_negated ⇒ Object
118 119 120 |
# File 'lib/shoulda/matchers/active_record/serialize_matcher.rb', line 118 def "Did not expect #{expectation}" end |
#matches?(subject) ⇒ 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 |