Exception: Assay::EqualityFailure

Inherits:
CompareFailure show all
Defined in:
lib/assay/assertions/equality_failure.rb

Constant Summary

Constants inherited from Assertion

Assertion::SIZE_LIMIT

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Assertion

assert, #assert, assertable_method, #assertion?, #fail?, #initialize, #negative?, #pass?, refute, #refute, #set_arguments, #set_negative, to_matcher

Constructor Details

This class inherits a constructor from Assay::Assertion

Class Method Details

.assertion_nameObject



9
10
11
# File 'lib/assay/assertions/equality_failure.rb', line 9

def self.assertion_name
  :equal
end

.assertion_operatorObject



14
15
16
# File 'lib/assay/assertions/equality_failure.rb', line 14

def self.assertion_operator
  :==
end

.fail?(exp, act) ⇒ Boolean

Check negated assertion.

Returns:

  • (Boolean)


24
25
26
# File 'lib/assay/assertions/equality_failure.rb', line 24

def self.fail?(exp, act)
  exp != act
end

.pass?(exp, act) ⇒ Boolean

Check assertion.

Returns:

  • (Boolean)


19
20
21
# File 'lib/assay/assertions/equality_failure.rb', line 19

def self.pass?(exp, act)
  exp == act
end

Instance Method Details

#to_sObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/assay/assertions/equality_failure.rb', line 29

def to_s
  return @mesg if @mesg
  return super unless @arguments.size == 2

  oper = @_negated ? "!=" : "=="
  iexp = @arguments[0].inspect
  iact = @arguments[1].inspect

  if iexp.size > SIZE_LIMIT or iact.size > SIZE_LIMIT
    diff = ANSI::Diff.new(iact, iexp)
    "a #{oper} b\na) #{diff.diff1}\nb) #{diff.diff2}"
  else
    "#{iact} #{oper} #{iexp}"
  end
end