Sha256: 4bdd8ed959351a8f3d4399e01b9c6bbb2d8b8c31c7066cc48006d3fe7d1c219c

Contents?: true

Size: 941 Bytes

Versions: 2

Compression:

Stored size: 941 Bytes

Contents

RSpec::Matchers.define :ensure_equality_of do |attribute|
  chain :to do |to|
    @to = to
  end

  chain :operator do |operator|
    @operator = operator
  end

  match do |model|
    raise Exception if @to.nil? || @operator.nil?

    value = model.send(attribute)
    model.send("#{@to}=", value)
    model.send("#{@operator}=", value)
    model.valid?

    if model.errors.has_key?(attribute)
      model.errors[attribute].include?(I18n.t('errors.messages.equality', attr: @to, operator: @operator))
    end
  end

  failure_message do |model|
    I18n.t('flash_validators.matchers.ensure_valid_equality_format_of.failure_message_for_should', model: model.class, attr: attribute.inspect, operator: "operator")
  end

  failure_message_when_negated do |model|
    I18n.t('flash_validators.matchers.ensure_valid_equality_format_of.failure_message_for_should_not', model: model.class, attr: attribute.inspect, operator: "operator")
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
flash_validators-1.1.0 lib/flash_validators/matchers/ensure_valid_equality_matcher_of.rb
flash_validators-1.0.0 lib/flash_validators/matchers/ensure_valid_equality_matcher_of.rb