Exception: RaiseAssay

Inherits:
RescueAssay show all
Defined in:
lib/assay/raise_assay.rb

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(*exceptions) ⇒ Object



44
45
46
47
# File 'lib/assay/raise_assay.rb', line 44

def self.assert_message(*exceptions)
  exp = exceptions.map{ |e| e.inspect }.join(' or ')
  "raise #{exp}" #, but was #{err} instead."
end

.fail?(*exceptions) ⇒ Boolean

Check negated assertion.

Returns:

  • (Boolean)


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

def self.fail?(*exceptions)
  exceptions = [RuntimeError] if exceptions.empty?
  begin
    yield
    true
  rescue Exception => e
    !exceptions.any? do |x|
      x.instance_of?(Module) ? x === e : e.class == x
    end
  end
end

.pass?(*exceptions) ⇒ Boolean

Check assertion.

Returns:

  • (Boolean)


11
12
13
14
15
16
17
18
19
20
21
# File 'lib/assay/raise_assay.rb', line 11

def self.pass?(*exceptions)
  exceptions = [RuntimeError] if exceptions.empty?
  begin
    yield
    false
  rescue Exception => e
    exceptions.any? do |x|
      x.instance_of?(Module) ? x === e : e.class == x
    end
  end
end

.refute_message(*exceptions) ⇒ Object



52
53
54
55
# File 'lib/assay/raise_assay.rb', line 52

def self.refute_message(*exceptions)
  exp = exceptions.map{ |e| e.inspect }.join(' or ')
  "! raise #{exp}" #, but was #{err} instead."
end