Class: ActiveAttr::Matchers::HaveAttributeMatcher

Inherits:
Object
  • Object
show all
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

Since:

Instance Method Summary (collapse)

Instance Method Details

- (HaveAttributeMatcher) of_type(type)

Specify that the attribute should have the given type

Examples:

Person's first name should be a String

describe Person do
  it { should have_attribute(:first_name).of_type(String) }
end

Since:

  • 0.5.0



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

- (HaveAttributeMatcher) with_default_value_of(default_value)

Specify that the attribute should have the given default value

Examples:

Person's first name should default to John

describe Person do
  it do
    should have_attribute(:first_name).with_default_value_of("John")
  end
end

Since:

  • 0.5.0



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 { actual_attribute_definition[:default] == default_value }
  self
end