Sha256: 1ec9cc71634038f4acf6735d5ad48e47ef96f75ad462dfa110c7974a75b14931

Contents?: true

Size: 393 Bytes

Versions: 9

Compression:

Stored size: 393 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)
  yield
  false
rescue StandardError => e
  e.is_a? exception
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
actionset-0.8.1 lib/helpers/throws.rb
actionset-0.8.0 lib/helpers/throws.rb
activeset-0.8.6 lib/helpers/throws.rb
activeset-0.8.5 lib/helpers/throws.rb
activeset-0.8.4 lib/helpers/throws.rb
activeset-0.8.3 lib/helpers/throws.rb
activeset-0.8.2 lib/helpers/throws.rb
activeset-0.8.1 lib/helpers/throws.rb
activeset-0.8.0 lib/helpers/throws.rb