class Shoulda::Matchers::ActiveRecord::NormalizeMatcher
@private
def attribute_does_not_match?(subject, attribute)
def attribute_does_not_match?(subject, attribute) return true unless normalize_attribute?(subject, attribute) @failure_message_when_negated = build_failure_message_when_negated(attribute) false end
def attribute_matches?(subject, attribute)
def attribute_matches?(subject, attribute) return true if normalize_attribute?(subject, attribute) @failure_message = build_failure_message( attribute, subject.class.normalize_value_for(attribute, from_value), ) false end
def build_failure_message(attribute, attribute_value)
def build_failure_message(attribute, attribute_value) %( Expected to normalize #{attribute.inspect} from ‹#{from_value.inspect}› to ‹#{to_value.inspect}› but it was normalized to ‹#{attribute_value.inspect}› ).squish end
def build_failure_message_when_negated(attribute)
def build_failure_message_when_negated(attribute) %( Expected to not normalize #{attribute.inspect} from ‹#{from_value.inspect}› to ‹#{to_value.inspect}› but it was normalized ).squish end
def description
def description %( normalize #{attributes.to_sentence(last_word_connector: ' and ')} from ‹#{from_value.inspect}› to ‹#{to_value.inspect}› ).squish end
def does_not_match?(subject)
def does_not_match?(subject) attributes.all? { |attribute| attribute_does_not_match?(subject, attribute) } end
def from(value)
def from(value) @from_value = value self end
def initialize(*attributes)
def initialize(*attributes) @attributes = attributes end
def matches?(subject)
def matches?(subject) attributes.all? { |attribute| attribute_matches?(subject, attribute) } end
def normalize_attribute?(subject, attribute)
def normalize_attribute?(subject, attribute) subject.class.normalize_value_for(attribute, from_value) == to_value end
def to(value)
def to(value) @to_value = value self end