Class: Shoulda::Matchers::ActiveModel::ValidationMatcher

Inherits:
Object
  • Object
show all
Includes:
Qualifiers::IgnoringInterferenceByWriter
Defined in:
lib/shoulda/matchers/active_model/validation_matcher.rb,
lib/shoulda/matchers/active_model/validation_matcher/build_description.rb

Defined Under Namespace

Classes: BuildDescription

Instance Attribute Summary

Attributes included from Qualifiers::IgnoringInterferenceByWriter

#ignore_interference_by_writer

Instance Method Summary collapse

Methods included from Qualifiers::IgnoringInterferenceByWriter

#ignoring_interference_by_writer

Constructor Details

#initialize(attribute) ⇒ ValidationMatcher

Returns a new instance of ValidationMatcher.



8
9
10
11
12
13
14
15
16
# File 'lib/shoulda/matchers/active_model/validation_matcher.rb', line 8

def initialize(attribute)
  super
  @attribute = attribute
  @expects_strict = false
  @subject = nil
  @last_submatcher_run = nil
  @expected_message = nil
  @expects_custom_validation_message = false
end

Instance Method Details

#allow_blankObject



27
28
29
30
# File 'lib/shoulda/matchers/active_model/validation_matcher.rb', line 27

def allow_blank
  options[:allow_blank] = true
  self
end

#descriptionObject



18
19
20
# File 'lib/shoulda/matchers/active_model/validation_matcher.rb', line 18

def description
  ValidationMatcher::BuildDescription.call(self, simple_description)
end

#does_not_match?(subject) ⇒ Boolean

Returns:

  • (Boolean)


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

def does_not_match?(subject)
  @subject = subject
  true
end

#expects_custom_validation_message?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/shoulda/matchers/active_model/validation_matcher.rb', line 50

def expects_custom_validation_message?
  @expects_custom_validation_message
end

#expects_strict?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/shoulda/matchers/active_model/validation_matcher.rb', line 37

def expects_strict?
  @expects_strict
end

#failure_messageObject



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/shoulda/matchers/active_model/validation_matcher.rb', line 64

def failure_message
  overall_failure_message.dup.tap do |message|
    if failure_reason.present?
      message << "\n"
      message << Shoulda::Matchers.word_wrap(
        failure_reason,
        indent: 2,
      )
    end
  end
end

#failure_message_when_negatedObject



76
77
78
79
80
81
82
83
84
85
86
# File 'lib/shoulda/matchers/active_model/validation_matcher.rb', line 76

def failure_message_when_negated
  overall_failure_message_when_negated.dup.tap do |message|
    if failure_reason.present?
      message << "\n"
      message << Shoulda::Matchers.word_wrap(
        failure_reason,
        indent: 2,
      )
    end
  end
end

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


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

def matches?(subject)
  @subject = subject
  false
end

#on(context) ⇒ Object



22
23
24
25
# File 'lib/shoulda/matchers/active_model/validation_matcher.rb', line 22

def on(context)
  @context = context
  self
end

#strictObject



32
33
34
35
# File 'lib/shoulda/matchers/active_model/validation_matcher.rb', line 32

def strict
  @expects_strict = true
  self
end

#with_message(expected_message) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/shoulda/matchers/active_model/validation_matcher.rb', line 41

def with_message(expected_message)
  if expected_message
    @expects_custom_validation_message = true
    @expected_message = expected_message
  end

  self
end