Sha256: 2d5d9dca559890e8062e81895c7397dacb6730de1a90dffc8d1385196660c7f4
Contents?: true
Size: 1.06 KB
Versions: 1
Compression:
Stored size: 1.06 KB
Contents
require_relative 'assertion' # Assert that a kind of exception class is rescued # from the execution of a block. # class RescueAssay < Assertion register :rescue # # Check assertion. # def self.pass?(*exceptions) exceptions = [RuntimeError] if exceptions.empty? begin yield false rescue Exception => e exceptions.any? do |x| x === e end end end # # Check negated assertion. # def self.fail?(*exceptions) exceptions = [RuntimeError] if exceptions.empty? begin yield true rescue Exception => e !exceptions.any? do |x| x === e end end end # TODO: How to add `but got class` message to error? # May have to override #assert! and #refute! method. # def self.assert_message(*exceptions) exp = exceptions.map{ |e| e.inspect }.join(' or ') "raise #{exp}" #, but was #{err} instead." end # def self.refute_message(*exceptions) exp = exceptions.map{ |e| e.inspect }.join(' or ') "! raise #{exp}" #, but was #{err} instead." end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
assay-0.4.0 | lib/assay/rescue_assay.rb |