Exception: Assay::ThrowFailure

Inherits:
ExecutionFailure show all
Defined in:
lib/assay/assertions/throw_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



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

def self.assertion_name
  :throws
end

.assertion_name!Object



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

def self.assertion_name!
  :not_thrown
end

.fail?(sym, &block) ⇒ Boolean

Passes if the block throws expected_symbol

assert_not_thrown :done do
  throw :chimp
end

FIXME: Is this correct?

Returns:

  • (Boolean)


45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/assay/assertions/throw_failure.rb', line 45

def self.fail?(sym, &block)
  pass = false
  catch(sym) do
    begin
      block.call
    rescue ArgumentError => err     # 1.9 exception
      #msg += ", not #{err.message.split(/ /).last}"
      pass = true
    rescue NameError => err         # 1.8 exception
      #msg += ", not #{err.name.inspect}"
      pass = true
    end
  end
  pass
end

.pass?(sym, &block) ⇒ Boolean

Passes if the block throws expected_symbol

assert_throws :done do
  throw :done
end

Returns:

  • (Boolean)


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/assay/assertions/throw_failure.rb', line 22

def self.pass?(sym, &block)
  pass = true
  catch(sym) do
    begin
      block.call
    rescue ArgumentError => err     # 1.9 exception
      #msg += ", not #{err.message.split(/ /).last}"
      pass = false
    rescue NameError => err         # 1.8 exception
      #msg += ", not #{err.name.inspect}"
      pass = false
    end
  end
  pass
end

Instance Method Details

#to_sObject



62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/assay/assertions/throw_failure.rb', line 62

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

  sym = @arguments[0].inspect

  if @_negated
    "Expected #{sym} to have been thrown"
  else
    "Expected #{sym} NOT to have been thrown"
  end
end