Sha256: 44d8ac217bf063cf38be07439249be5b07e02718b3417162d7d546d65b8387db

Contents?: true

Size: 412 Bytes

Versions: 6

Compression:

Stored size: 412 Bytes

Contents

# frozen_string_literal: true

# Returns a Boolean for whether the block raises the Exception expected
#
# throws?(StandardError) { raise }
# => true
# throws?(NameError) { raise NameError }
# => true
# throws?(NoMethodError) { raise NameError }
# => false
# throws?(StandardError) { 'foo' }
# => false

def throws?(exception) # &block
  yield
  return false
rescue Exception => e
  return e.is_a? exception
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
activeset-0.6.5 lib/helpers/throws.rb
activeset-0.6.4 lib/helpers/throws.rb
activeset-0.6.3 lib/helpers/throws.rb
activeset-0.6.2 lib/helpers/throws.rb
activeset-0.6.1 lib/helpers/throws.rb
activeset-0.6.0 lib/helpers/throws.rb