Module: Speck::Mixins::Proc

Defined in:
lib/speck/core_ext/check_mixins.rb

Constant Summary collapse

Target =
::Proc

Instance Method Summary collapse

Instance Method Details

#check_exception(exception = Exception) ⇒ Object

This method is responsible for checking that a particular proc raises a particular exception type when called.



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/speck/core_ext/check_mixins.rb', line 50

def check_exception exception = Exception
  # TODO: Should we allow specks in the root environment? Could be useful
  #       for quick checks…
  raise Exception::NoEnvironment unless Speck.current
  
  file, line, _ = Kernel::caller.first.split(':')
  source = File.open(file).readlines[line.to_i - 1]
  source.strip!
  source = source.partition(".check_exception").first
  # TODO: Get rid of the "->{…}" around the resulting string.
  
  Speck.current.checks <<
    Speck::Check.new(->(){
      begin
        self.call
      rescue exception
        return true
      end
      return false
    }, source)
end