Exception: Expectation::Matcher::Mismatch

Inherits:
ArgumentError
  • Object
show all
Defined in:
lib/expectation/matcher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value, expectation, info = nil) ⇒ Mismatch

Returns a new instance of Mismatch.



15
16
17
18
19
# File 'lib/expectation/matcher.rb', line 15

def initialize(value, expectation, info = nil)
  @value = value
  @expectation = expectation
  @info = info
end

Instance Attribute Details

#expectationObject (readonly)

Returns the value of attribute expectation.



13
14
15
# File 'lib/expectation/matcher.rb', line 13

def expectation
  @expectation
end

#infoObject (readonly)

Returns the value of attribute info.



13
14
15
# File 'lib/expectation/matcher.rb', line 13

def info
  @info
end

#valueObject (readonly)

Returns the value of attribute value.



13
14
15
# File 'lib/expectation/matcher.rb', line 13

def value
  @value
end

Instance Method Details

#to_sObject



21
22
23
24
25
26
27
28
# File 'lib/expectation/matcher.rb', line 21

def to_s
  message = "#{value.inspect} does not match #{expectation.inspect}"
  case info
  when nil    then  message
  when Fixnum then  "#{message}, at index #{info}"
  else              "#{message}, at key #{info.inspect}"
  end
end