Class: NormalizeDigits::Matchers::NormalizeDigitsForMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/normalize_digits/matchers.rb

Overview

Matcher class

Instance Method Summary collapse

Constructor Details

#initialize(attribute) ⇒ NormalizeDigitsForMatcher

Returns a new instance of NormalizeDigitsForMatcher.



16
17
18
19
# File 'lib/normalize_digits/matchers.rb', line 16

def initialize(attribute)
  @attribute = attribute
  @options = {}
end

Instance Method Details

#descriptionObject



48
49
50
# File 'lib/normalize_digits/matchers.rb', line 48

def description
  "Englishize non-english digits from #{@attribute}"
end

#failure_messageObject Also known as: failure_message_for_should

RSpec 3.x



30
31
32
# File 'lib/normalize_digits/matchers.rb', line 30

def failure_message
  "Expected to be normalized from #{@attribute}, but it was not"
end

#failure_message_when_negatedObject Also known as: failure_message_for_should_not, negative_failure_message

RSpec 3.x



38
39
40
# File 'lib/normalize_digits/matchers.rb', line 38

def failure_message_when_negated
  "Expected to remain on #{@attribute}, but it was normalized"
end

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
24
25
26
27
# File 'lib/normalize_digits/matchers.rb', line 21

def matches?(subject)
  return false unless subject.send(@attribute).is_a?(String)

  subject.send("#{@attribute}=", "०۰٠")
  subject.valid?
  subject.send(@attribute) == "000"
end