Class: AttributeNormalizer::RSpecMatcher::NormalizeAttribute

Inherits:
Object
  • Object
show all
Defined in:
lib/attribute_normalizer/rspec_matcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(attribute) ⇒ NormalizeAttribute

Returns a new instance of NormalizeAttribute.


11
12
13
14
# File 'lib/attribute_normalizer/rspec_matcher.rb', line 11

def initialize(attribute)
  @attribute = attribute
  @from = ''
end

Instance Method Details

#descriptionObject


16
17
18
# File 'lib/attribute_normalizer/rspec_matcher.rb', line 16

def description
  "normalize #{@attribute} from #{@from.nil? ? 'nil' : "\"#{@from}\""} to #{@to.nil? ? 'nil' : "\"#{@to}\""}"
end

#failure_messageObject


20
21
22
# File 'lib/attribute_normalizer/rspec_matcher.rb', line 20

def failure_message
  "#{@attribute} did not normalize as expected! \"#{@subject.send(@attribute)}\" != #{@to.nil? ? 'nil' : "\"#{@to}\""}"
end

#failure_message_when_negatedObject Also known as: negative_failure_message


24
25
26
# File 'lib/attribute_normalizer/rspec_matcher.rb', line 24

def failure_message_when_negated
  "expected #{@attribute} to not be normalized from #{@from.nil? ? 'nil' : "\"#{@from}\""} to #{@to.nil? ? 'nil' : "\"#{@to}\""}"
end

#from(value) ⇒ Object


29
30
31
32
# File 'lib/attribute_normalizer/rspec_matcher.rb', line 29

def from(value)
  @from = value
  self
end

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)

39
40
41
42
43
44
# File 'lib/attribute_normalizer/rspec_matcher.rb', line 39

def matches?(subject)
  @subject = subject
  @subject.send("#{@attribute}=", @from)

  @subject.send(@attribute) == @to
end

#to(value) ⇒ Object


34
35
36
37
# File 'lib/attribute_normalizer/rspec_matcher.rb', line 34

def to(value)
  @to = value
  self
end