PageRenderTime 47ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/rex/exceptions.rb.ut.rb

https://bitbucket.org/technopunk2099/metasploit-framework
Ruby | 45 lines | 32 code | 10 blank | 3 comment | 3 complexity | 7a7d67363e0e2b8eba9a1ca134daeb82 MD5 | raw file
Possible License(s): BSD-3-Clause, Apache-2.0, LGPL-2.1, GPL-2.0, MIT
  1. #!/usr/bin/env ruby
  2. # -*- coding: binary -*-
  3. $:.unshift(File.join(File.dirname(__FILE__), '..'))
  4. require 'test/unit'
  5. require 'rex/exceptions'
  6. module Rex
  7. module Exceptions
  8. class UnitTest < Test::Unit::TestCase
  9. def test_exceptions
  10. Rex.constants.each { |const|
  11. mod = Rex.const_get(const)
  12. if ((mod.kind_of?(Class) == false) ||
  13. (mod.ancestors.include?(Rex::Exception) == false))
  14. next
  15. end
  16. begin
  17. raise mod.new
  18. rescue ::ArgumentError
  19. rescue mod => detail
  20. assert_respond_to(detail, 'to_s', "#{mod} does not implement to_s")
  21. assert_not_nil(detail.to_s, "invalid to_s")
  22. end
  23. }
  24. # Test communication error detail strings
  25. begin
  26. raise ConnectionRefused.new('127.0.0.1', 4444)
  27. rescue HostCommunicationError => detail
  28. assert_match(/^The connection(.*)\(127.0.0.1:4444\)/, detail.to_s)
  29. assert_equal('127.0.0.1', detail.host)
  30. assert_equal(4444, detail.port)
  31. end
  32. end
  33. end
  34. end
  35. end