class Shoulda::Matchers::ActiveModel::ValidationMatcher

@private

Attributes

failure_message[R]
failure_message_for_should[R]

Public Class Methods

new(attribute) click to toggle source
# File lib/shoulda/matchers/active_model/validation_matcher.rb, line 10
def initialize(attribute)
  @attribute = attribute
  @strict = false
end

Public Instance Methods

failure_message_for_should_not()
failure_message_when_negated() click to toggle source
# File lib/shoulda/matchers/active_model/validation_matcher.rb, line 25
def failure_message_when_negated
  @failure_message_when_negated || @failure_message
end
matches?(subject) click to toggle source
# File lib/shoulda/matchers/active_model/validation_matcher.rb, line 30
def matches?(subject)
  @subject = subject
  false
end
on(context) click to toggle source
# File lib/shoulda/matchers/active_model/validation_matcher.rb, line 15
def on(context)
  @context = context
  self
end
strict() click to toggle source
# File lib/shoulda/matchers/active_model/validation_matcher.rb, line 20
def strict
  @strict = true
  self
end

Private Instance Methods

allow_value_matcher(value, message) click to toggle source
# File lib/shoulda/matchers/active_model/validation_matcher.rb, line 63
def allow_value_matcher(value, message)
  matcher = AllowValueMatcher.
    new(value).
    for(@attribute).
    on(@context).
    with_message(message)

  if strict?
    matcher.strict
  else
    matcher
  end
end
allows_value_of(value, message = nil) { |allow| ... } click to toggle source
# File lib/shoulda/matchers/active_model/validation_matcher.rb, line 37
def allows_value_of(value, message = nil, &block)
  allow = allow_value_matcher(value, message)
  yield allow if block_given?

  if allow.matches?(@subject)
    @failure_message_when_negated = allow.failure_message_when_negated
    true
  else
    @failure_message = allow.failure_message
    false
  end
end
disallow_value_matcher(value, message) click to toggle source
# File lib/shoulda/matchers/active_model/validation_matcher.rb, line 77
def disallow_value_matcher(value, message)
  matcher = DisallowValueMatcher.
    new(value).
    for(@attribute).
    on(@context).
    with_message(message)

  if strict?
    matcher.strict
  else
    matcher
  end
end
disallows_value_of(value, message = nil) { |disallow| ... } click to toggle source
# File lib/shoulda/matchers/active_model/validation_matcher.rb, line 50
def disallows_value_of(value, message = nil, &block)
  disallow = disallow_value_matcher(value, message)
  yield disallow if block_given?

  if disallow.matches?(@subject)
    @failure_message_when_negated = disallow.failure_message_when_negated
    true
  else
    @failure_message = disallow.failure_message
    false
  end
end
strict?() click to toggle source
# File lib/shoulda/matchers/active_model/validation_matcher.rb, line 91
def strict?
  @strict
end