Class: ActiveAttr::Matchers::HaveAttributeMatcher
- Inherits:
-
Object
- Object
- ActiveAttr::Matchers::HaveAttributeMatcher
- Defined in:
- lib/active_attr/matchers/have_attribute_matcher.rb
Overview
Verifies that an ActiveAttr-based model has an attribute matching the given criteria. See #have_attribute
Instance Method Summary collapse
-
#of_type(type) ⇒ HaveAttributeMatcher
Specify that the attribute should have the given type.
-
#with_default_value_of(default_value) ⇒ HaveAttributeMatcher
Specify that the attribute should have the given default value.
Instance Method Details
#of_type(type) ⇒ HaveAttributeMatcher
Specify that the attribute should have the given type
53 54 55 56 57 58 59 |
# File 'lib/active_attr/matchers/have_attribute_matcher.rb', line 53 def of_type(type) @attribute_options[:type] = type @description << " of type #{type}" @expected_ancestors << "ActiveAttr::TypecastedAttributes" @attribute_expectations << lambda { @model_class._attribute_type(attribute_name) == type } self end |
#with_default_value_of(default_value) ⇒ HaveAttributeMatcher
Specify that the attribute should have the given default value
75 76 77 78 79 80 81 |
# File 'lib/active_attr/matchers/have_attribute_matcher.rb', line 75 def with_default_value_of(default_value) @attribute_options[:default] = default_value @description << " with a default value of #{default_value.inspect}" @expected_ancestors << "ActiveAttr::AttributeDefaults" @attribute_expectations << lambda { @model_class.allocate.send(:_attribute_default, @attribute_name) == default_value } self end |