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 @failure_message = nil @failure_message_when_negated = nil end
Public Instance Methods
failure_message_when_negated()
click to toggle source
# File lib/shoulda/matchers/active_model/validation_matcher.rb, line 27 def failure_message_when_negated @failure_message_when_negated || @failure_message end
Also aliased as: failure_message_for_should_not
matches?(subject)
click to toggle source
# File lib/shoulda/matchers/active_model/validation_matcher.rb, line 32 def matches?(subject) @subject = subject false end
on(context)
click to toggle source
# File lib/shoulda/matchers/active_model/validation_matcher.rb, line 17 def on(context) @context = context self end
strict()
click to toggle source
# File lib/shoulda/matchers/active_model/validation_matcher.rb, line 22 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 65 def allow_value_matcher(value, message) matcher = AllowValueMatcher.new(value).for(@attribute). with_message(message) if defined?(@context) matcher.on(@context) end if strict? matcher.strict end matcher end
allows_value_of(value, message = nil) { |allow| ... }
click to toggle source
# File lib/shoulda/matchers/active_model/validation_matcher.rb, line 39 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 80 def disallow_value_matcher(value, message) matcher = DisallowValueMatcher.new(value).for(@attribute). with_message(message) if defined?(@context) matcher.on(@context) end if strict? matcher.strict end matcher end
disallows_value_of(value, message = nil) { |disallow| ... }
click to toggle source
# File lib/shoulda/matchers/active_model/validation_matcher.rb, line 52 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 95 def strict? @strict end