Sha256: 51d7c78622efe28d9d5e20cc1f3444a79076ad40829b1591ebc0a8a859e5730f

Contents?: true

Size: 938 Bytes

Versions: 2

Compression:

Stored size: 938 Bytes

Contents

#!/usr/bin/env ruby
# -*- coding: binary -*-

$:.unshift(File.join(File.dirname(__FILE__), '..'))

require 'test/unit'
require 'rex/exceptions'

module Rex
module Exceptions

class UnitTest < Test::Unit::TestCase

	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

end

end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
librex-0.0.68 lib/rex/exceptions.rb.ut.rb
librex-0.0.66 lib/rex/exceptions.rb.ut.rb