Exception: CompareAssay

Inherits:
Assertion show all
Defined in:
lib/assay/compare_assay.rb

Overview

Compare assertion serves primarily as a base class for other more specific comparison assertions.

In itself it can be used to test a comparision made by #<=>.

Constant Summary

Constants inherited from Assertion

Assertion::SIZE_LIMIT

Constants included from Assay::Assertable

Assay::Assertable::SIZE_LIMIT

Class Method Summary collapse

Methods inherited from Assertion

by_name, by_operator, inherited, register, subclasses

Methods included from Assay::Assertable

#[], #assert!, #assert_message, #assertive_name, #assertor, #fail?, #operator, #pass?, #refute!, #refute_message

Class Method Details

.assert_message(subject, criterion, result = 0) ⇒ Object

Error message for campare assertion.



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/assay/compare_assay.rb', line 25

def self.assert_message(subject, criterion, result=0)
  a  = subject.inspect
  b  = criterion.inspect
  r  = result.inspect

  if a.size > SIZE_LIMIT or b.size > SIZE_LIMIT
    "a <=> b == #{r}\na) #{a}\nb) #{b}"
  else
    "#{a} <=> #{b} == #{r}"
  end
end

.pass?(subject, criterion, result = 0) ⇒ Boolean

Check assertion using ‘<=>`.

Returns:

  • (Boolean)


18
19
20
# File 'lib/assay/compare_assay.rb', line 18

def self.pass?(subject, criterion, result=0)
  (subject <=> criterion) == result
end