Class: Rex::Exceptions::UnitTest

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
lib/rex/exceptions.rb.ut.rb

Instance Method Summary collapse

Instance Method Details

#test_exceptionsObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/rex/exceptions.rb.ut.rb', line 13

def test_exceptions
	Rex.constants.each { |const|
		mod = Rex.const_get(const)

		if ((mod.kind_of?(Class) == false) ||
		    (mod.ancestors.include?(Rex::Exception) == false))
			next
		end

		begin
			raise mod.new
		rescue ::ArgumentError
		rescue mod => detail
			assert_respond_to(detail, 'to_s', "#{mod} does not implement to_s")
			assert_not_nil(detail.to_s, "invalid to_s")
		end
	}

	# Test communication error detail strings
	begin
		raise ConnectionRefused.new('127.0.0.1', 4444)
	rescue HostCommunicationError => detail
		assert_match(/^The connection(.*)\(127.0.0.1:4444\)/, detail.to_s)
		assert_equal('127.0.0.1', detail.host)
		assert_equal(4444, detail.port)
	end
end