Class: Test::Unit::Assertions::ThrowTagExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/test/unit/assertions.rb

Constant Summary collapse

UncaughtThrowPatterns =
{
  NameError => /^uncaught throw `(.+)'$/,
  ArgumentError => /^uncaught throw (`.+'|.+)$/,
  ThreadError => /^uncaught throw `(.+)' in thread /,
}
@@have_uncaught_throw_error =
const_defined?(:UncaughtThrowError)

Instance Method Summary collapse

Constructor Details

#initialize(error) ⇒ ThrowTagExtractor

Returns a new instance of ThrowTagExtractor.



755
756
757
# File 'lib/test/unit/assertions.rb', line 755

def initialize(error)
  @error = error
end

Instance Method Details

#extract_tagObject



759
760
761
762
763
764
765
766
767
768
769
770
771
# File 'lib/test/unit/assertions.rb', line 759

def extract_tag
  tag = nil
  if @@have_uncaught_throw_error
    return nil unless @error.is_a?(UncaughtThrowError)
    tag = @error.tag
  else
    pattern = UncaughtThrowPatterns[@error.class]
    return nil if pattern.nil?
    return nil unless pattern =~ @error.message
    tag = $1
  end
  normalize_tag(tag)
end