Exception: Assay::RaiseFailure

Inherits:
ExecutionFailure show all
Defined in:
lib/assay/assertions/raise_failure.rb

Constant Summary

Constants inherited from Assertion

Assertion::SIZE_LIMIT

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Assertion

#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

.assert(exp, msg = nil, call = nil) ⇒ Object

:yeild:



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/assay/assertions/raise_failure.rb', line 17

def self.assert(exp, msg=nil, call=nil) #:yeild:
  begin
    yield
    #msg = msg || fail_message(exp)
    test = false
    args = [exp]
  rescue Exception => err
    #msg = msg || fail_message(exp, err)
    test = (exp === err)
    args = [exp, err]
  end
  if !test
    err = new(msg, :backtrace=>(call || caller), :arguments=>args)
    fail err
  end
end

.assert!(exp, msg = nil, call = nil) ⇒ Object

:yield:



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/assay/assertions/raise_failure.rb', line 35

def self.assert!(exp, msg=nil, call=nil) #:yield:
  begin
    yield
    test = true
    args = [exp]
  rescue Exception => err
    #msg = msg || fail_message!(exp, err)
    test = (exp === err)
    args = [exp, err]
  end
  if !test
    err = new(msg, :backtrace=>(call || caller), :arguments=>args)
    fail err
  end
end

.assertion_nameObject



8
9
10
# File 'lib/assay/assertions/raise_failure.rb', line 8

def self.assertion_name
  :raises
end

.assertion_name!Object



12
13
14
# File 'lib/assay/assertions/raise_failure.rb', line 12

def self.assertion_name!
  :not_raised
end

.fail?(*exp) ⇒ Boolean

Check negated assertion.

Note: This is not used by the #assert! method.

Returns:

  • (Boolean)


66
67
68
69
70
71
72
73
# File 'lib/assay/assertions/raise_failure.rb', line 66

def self.fail?(*exp)
  begin
    yield
    true
  rescue Exception => e
    !exp.any?{ |x| x === e }
  end
end

.pass?(*exp) ⇒ Boolean

Check assertion.

Note: This is not used by the #assert method.

Returns:

  • (Boolean)


54
55
56
57
58
59
60
61
# File 'lib/assay/assertions/raise_failure.rb', line 54

def self.pass?(*exp)
  begin
    yield
    false
  rescue Exception => e
    exp.any?{ |x| x === e }
  end
end

Instance Method Details

#to_sObject

TODO: how to add ‘but got class` instead.



76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/assay/assertions/raise_failure.rb', line 76

def to_s
  return super unless @arguments.size == 1

  exp = @arguments[0].inspect
  #err = @_arguments[1].inspect

  if @_negated
    "Expected #{exp} NOT to be raised"
  else
    "Expected #{exp} to be raised" #, but was #{err} instead."
  end
end