module MiniTest::Matchers::ActiveModel

Public Instance Methods

ensure_length_of(attr)
Alias for: validate_length_of
ensure_size_of(attr)
Alias for: validate_length_of
validate_acceptance_of(attr) click to toggle source

Ensures that the model is invalid if the given attribute is not accepted.

Options:

# File lib/matchers/validate_acceptance_matcher.rb, line 11
def validate_acceptance_of attr
  ValidateAcceptanceMatcher.new attr
end
validate_associated(association_name) click to toggle source

Ensures that the model is invalid if the given association name is not valid itself.

it { must validate_associated(:parent)   }
it { must validate_associated(:children) }
# File lib/matchers/validate_associated_matcher.rb, line 9
def validate_associated association_name
  ValidateAssociated.new association_name
end
validate_confirmation_of(attr) click to toggle source

Ensures that the model’s attribute matches confirmation.

it { must validate_confirmation_of :password }
# File lib/matchers/validate_confirmation_matcher.rb, line 7
def validate_confirmation_of attr
  ValidationMatcher.new attr, :confirmation
end
validate_exclusion_of(attr) click to toggle source

TODO: Add documentation

# File lib/matchers/validate_exclusion_matcher.rb, line 5
def validate_exclusion_of attr
  ValidateExclusionMatcher.new attr
end
validate_format_of(attr) click to toggle source

Ensures that the model is invalid if the given attribute is not formatted correctly.

Options:

  • to_allow - string to test against that it is valid.

  • to_not_allow - string to test against that it is not valid.

    it { must validate_format_of(:email).to_allow(‘foo@bar.com’) } it { must validate_format_of(:email).to_not_allow(‘foo_bar_com’) }

# File lib/matchers/validate_format_matcher.rb, line 13
def validate_format_of attr
  ValidateFormatMatcher.new attr
end
validate_inclusion_of(attr) click to toggle source

TODO: Add documentation.

# File lib/matchers/validate_inclusion_matcher.rb, line 5
def validate_inclusion_of attr
  ValidateInclusionMatcher.new attr
end
validate_length_of(attr) click to toggle source

Ensures that the length/size of the attribute is validated. You must supply at least one of the following options:

Options:

This matcher is also aliased as:

  • validate_size_of.

  • ensure_length_of.

  • ensure_size_of.

So you can do something like:

it { must ensure_length_of(:name).is_at_least(10) }
it { must ensure_size_of(:name).is_at_most(100) }
it { must validate_size_of(:name).in(10..100) }
# File lib/matchers/validate_length_matcher.rb, line 39
def validate_length_of attr
  ValidateLengthMatcher.new attr
end
validate_presence_of(attr) click to toggle source

Ensures that the model is invalid if the given attribute is not present.

it { must validate_presence_of(:name) }
# File lib/matchers/validate_presence_matcher.rb, line 7
def validate_presence_of attr
  ValidationMatcher.new attr, :presence
end
validate_size_of(attr)
Alias for: validate_length_of
validate_uniqueness_of(attr) click to toggle source

Ensures that the model is invalid if the given attribute is not unique.

Options:

# File lib/matchers/validate_uniqueness_matcher.rb, line 15
def validate_uniqueness_of attr
  ValidateUniquenessMatcher.new attr
end