Class: Shoulda::ActiveRecord::Matchers::ValidateFormatOfMatcher

Inherits:
ValidationMatcher show all
Defined in:
lib/shoulda/active_record/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_record/matchers/validate_format_of_matcher.rb', line 29

def initialize(attribute)
  super
end

Instance Method Details

#descriptionObject



57
58
59
# File 'lib/shoulda/active_record/matchers/validate_format_of_matcher.rb', line 57

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

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
53
54
55
# File 'lib/shoulda/active_record/matchers/validate_format_of_matcher.rb', line 50

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



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

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_record/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_record/matchers/validate_format_of_matcher.rb', line 33

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