class Shoulda::Matchers::ActiveModel::ValidationMatcher::BuildDescription

@private

Attributes

main_description[R]
matcher[R]

Public Class Methods

call(matcher, main_description) click to toggle source
# File lib/shoulda/matchers/active_model/validation_matcher/build_description.rb, line 7
def self.call(matcher, main_description)
  new(matcher, main_description).call
end
new(matcher, main_description) click to toggle source
# File lib/shoulda/matchers/active_model/validation_matcher/build_description.rb, line 11
def initialize(matcher, main_description)
  @matcher = matcher
  @main_description = main_description
end

Public Instance Methods

call() click to toggle source
# File lib/shoulda/matchers/active_model/validation_matcher/build_description.rb, line 16
def call
  if description_clauses_for_qualifiers.any?
    main_description +
      ', ' +
      description_clauses_for_qualifiers.to_sentence
  else
    main_description
  end
end

Private Instance Methods

description_clauses_for_qualifiers() click to toggle source
# File lib/shoulda/matchers/active_model/validation_matcher/build_description.rb, line 32
def description_clauses_for_qualifiers
  description_clauses = []

  if matcher.try(:expects_to_allow_blank?)
    description_clauses << 'but only if it is not blank'
  elsif matcher.try(:expects_to_allow_nil?)
    description_clauses << 'but only if it is not nil'
  end

  if matcher.try(:expects_strict?)
    description_clauses << 'raising a validation exception'

    if matcher.try(:expects_custom_validation_message?)
      description_clauses.last << ' with a custom message'
    end

    description_clauses.last << ' on failure'
  elsif matcher.try(:expects_custom_validation_message?)
    description_clauses <<
      'producing a custom validation error on failure'
  end

  description_clauses
end