Class: MiniTest::Matchers::ActiveModel::ValidateFormatMatcher

Inherits:
ValidationMatcher show all
Defined in:
lib/matchers/validate_format_matcher.rb

Instance Method Summary collapse

Methods inherited from ValidationMatcher

#failure_message, #negative_failure_message, #on, #with_message

Methods included from Helpers

#class_of, #to_sentence

Constructor Details

#initialize(attr) ⇒ ValidateFormatMatcher

Returns a new instance of ValidateFormatMatcher.



20
21
22
23
24
# File 'lib/matchers/validate_format_matcher.rb', line 20

def initialize attr
  @valid, @invalid = nil

  super attr, :format
end

Instance Method Details

#descriptionObject



51
52
53
54
55
56
# File 'lib/matchers/validate_format_matcher.rb', line 51

def description
  desc = []
  desc << " allowing the value #{@valid.inspect}" if @valid
  desc << " not allowing the value #{@invalid.inspect}" if @invalid
  super << desc.to_sentence
end

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
43
44
45
46
47
48
49
# File 'lib/matchers/validate_format_matcher.rb', line 40

def matches? subject
  validate_invalid_options! @valid, @invalid

  return false unless @result = super(subject)

  check_valid_value   if @valid
  check_invalid_value if @invalid

  @result
end

#to_allow(valid_value) ⇒ Object



26
27
28
29
30
31
# File 'lib/matchers/validate_format_matcher.rb', line 26

def to_allow valid_value
  raise 'You must not call both to_allow and to_not_allow' if @invalid

  @valid = valid_value
  self
end

#to_not_allow(invalid_value) ⇒ Object



33
34
35
36
37
38
# File 'lib/matchers/validate_format_matcher.rb', line 33

def to_not_allow invalid_value
  raise 'You must not call both to_allow and to_not_allow' if @valid

  @invalid = invalid_value
  self
end