Class: Normalizr::RSpec::Matcher::Normalization

Inherits:
Object
  • Object
show all
Defined in:
lib/normalizr/rspec/matcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(attribute) ⇒ Normalization

Returns a new instance of Normalization.



11
12
13
14
# File 'lib/normalizr/rspec/matcher.rb', line 11

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

Instance Method Details

#descriptionObject



16
17
18
# File 'lib/normalizr/rspec/matcher.rb', line 16

def description
  "normalize #{@attribute} from #{display(@from)} to #{display(@to)}"
end

#failure_messageObject



20
21
22
# File 'lib/normalizr/rspec/matcher.rb', line 20

def failure_message
  "#{@attribute} did not normalize as expected! #{display(@subject.send(@attribute))} != #{display(@to)}"
end

#failure_message_when_negatedObject Also known as: negative_failure_message



24
25
26
# File 'lib/normalizr/rspec/matcher.rb', line 24

def failure_message_when_negated
  "expected #{@attribute} to not be normalized from #{display(@from)} to #{display(@to)}"
end

#from(value) ⇒ Object



30
31
32
33
# File 'lib/normalizr/rspec/matcher.rb', line 30

def from(value)
  @from = value
  self
end

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
43
44
# File 'lib/normalizr/rspec/matcher.rb', line 40

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

#to(value) ⇒ Object



35
36
37
38
# File 'lib/normalizr/rspec/matcher.rb', line 35

def to(value)
  @to = value
  self
end