Class: Virtus::Matchers::HaveAttributeMatcher
- Inherits:
-
Object
- Object
- Virtus::Matchers::HaveAttributeMatcher
- Defined in:
- lib/virtus/matchers/have_attribute_matcher.rb
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
-
#initialize(name, type) ⇒ HaveAttributeMatcher
constructor
A new instance of HaveAttributeMatcher.
- #matches?(klass) ⇒ Boolean
Constructor Details
#initialize(name, type) ⇒ HaveAttributeMatcher
Returns a new instance of HaveAttributeMatcher.
6 7 8 9 |
# File 'lib/virtus/matchers/have_attribute_matcher.rb', line 6 def initialize(name, type) @name = name @type = type end |
Instance Method Details
#description ⇒ Object
23 24 25 26 |
# File 'lib/virtus/matchers/have_attribute_matcher.rb', line 23 def description type = @type.class == Array ? "Array#{@type}" : @type "have attribute #{@name} of type #{type}" end |
#failure_message ⇒ Object
28 29 30 |
# File 'lib/virtus/matchers/have_attribute_matcher.rb', line 28 def "expected #{@klass} to #{description}" end |
#matches?(klass) ⇒ Boolean
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/virtus/matchers/have_attribute_matcher.rb', line 11 def matches?(klass) @klass = klass attribute = @klass.attribute_set[@name] return false unless attribute if @type.class == Array attribute.primitive == Array && attribute.[:member_type].primitive == @type.first else attribute.primitive == @type end end |