/tools/Ruby/lib/ruby/1.8/test/unit/error.rb

http://github.com/agross/netopenspace · Ruby · 56 lines · 30 code · 11 blank · 15 comment · 0 complexity · c529aef3031106e9f2a1c94b126e8cfe MD5 · raw file

  1. #--
  2. #
  3. # Author:: Nathaniel Talbott.
  4. # Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
  5. # License:: Ruby license.
  6. require 'test/unit/util/backtracefilter'
  7. module Test
  8. module Unit
  9. # Encapsulates an error in a test. Created by
  10. # Test::Unit::TestCase when it rescues an exception thrown
  11. # during the processing of a test.
  12. class Error
  13. include Util::BacktraceFilter
  14. attr_reader(:test_name, :exception)
  15. SINGLE_CHARACTER = 'E'
  16. # Creates a new Error with the given test_name and
  17. # exception.
  18. def initialize(test_name, exception)
  19. @test_name = test_name
  20. @exception = exception
  21. end
  22. # Returns a single character representation of an error.
  23. def single_character_display
  24. SINGLE_CHARACTER
  25. end
  26. # Returns the message associated with the error.
  27. def message
  28. "#{@exception.class.name}: #{@exception.message}"
  29. end
  30. # Returns a brief version of the error description.
  31. def short_display
  32. "#@test_name: #{message.split("\n")[0]}"
  33. end
  34. # Returns a verbose version of the error description.
  35. def long_display
  36. backtrace = filter_backtrace(@exception.backtrace).join("\n ")
  37. "Error:\n#@test_name:\n#{message}\n #{backtrace}"
  38. end
  39. # Overridden to return long_display.
  40. def to_s
  41. long_display
  42. end
  43. end
  44. end
  45. end