Class: Shoulda::ActiveModel::Matchers::ValidateFormatOfMatcher

Inherits:
ValidationMatcher show all
Defined in:
lib/shoulda/active_model/matchers/validate_format_of_matcher.rb

Overview

:nodoc:

Instance Attribute Summary

Attributes inherited from ValidationMatcher

#failure_message

Instance Method Summary collapse

Methods inherited from ValidationMatcher

#negative_failure_message

Constructor Details

#initialize(attribute) ⇒ ValidateFormatOfMatcher

Returns a new instance of ValidateFormatOfMatcher.



29
30
31
# File 'lib/shoulda/active_model/matchers/validate_format_of_matcher.rb', line 29

def initialize(attribute)
  super
end

Instance Method Details

#descriptionObject



59
60
61
# File 'lib/shoulda/active_model/matchers/validate_format_of_matcher.rb', line 59

def description
  "#{@attribute} have a valid format"
end

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
55
56
57
# File 'lib/shoulda/active_model/matchers/validate_format_of_matcher.rb', line 52

def matches?(subject)
  super(subject)
  @expected_message ||= :blank
  return disallows_value_of(@value_to_fail, @expected_message) if @value_to_fail
  allows_value_of(@value_to_pass, @expected_message) if @value_to_pass
end

#not_with(value) ⇒ Object



45
46
47
48
49
# File 'lib/shoulda/active_model/matchers/validate_format_of_matcher.rb', line 45

def not_with(value)
  raise "You may not call both with and not_with" if @value_to_pass
  @value_to_fail = value
  self
end

#with(value) ⇒ Object



38
39
40
41
42
# File 'lib/shoulda/active_model/matchers/validate_format_of_matcher.rb', line 38

def with(value)
  raise "You may not call both with and not_with" if @value_to_fail
  @value_to_pass = value
  self
end

#with_message(message) ⇒ Object



33
34
35
36
# File 'lib/shoulda/active_model/matchers/validate_format_of_matcher.rb', line 33

def with_message(message)
  @expected_message = message if message
  self
end