Class: CapitalizeAttributes::Matchers::CapitalizeAttributeMatcher

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

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ CapitalizeAttributeMatcher

Returns a new instance of CapitalizeAttributeMatcher.



17
18
19
20
# File 'lib/capitalize_attributes/matchers.rb', line 17

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

Instance Method Details

#descriptionObject



44
45
46
# File 'lib/capitalize_attributes/matchers.rb', line 44

def description
  "capitalize #{@attributes.map { |el| "##{el}" }.to_sentence}"
end

#failure_messageObject Also known as: failure_message_for_should

RSpec 3.x



31
32
33
# File 'lib/capitalize_attributes/matchers.rb', line 31

def failure_message # RSpec 3.x
  "Expected #{@attribute} to be capitalized, but it was not"
end

#failure_message_when_negatedObject Also known as: failure_message_for_should_not, negative_failure_message

RSpec 3.x



37
38
39
# File 'lib/capitalize_attributes/matchers.rb', line 37

def failure_message_when_negated # RSpec 3.x
  "Expected #{@attribute} not to be capitalized, but it was"
end

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
25
26
27
28
29
# File 'lib/capitalize_attributes/matchers.rb', line 22

def matches?(subject)
  @attributes.all? do |attribute|
    @attribute = attribute
    subject.send("#{@attribute}=", "string")
    subject.validate
    subject.send(@attribute) == "String"
  end
end