Class: Testotron::Tests::SMTP

Inherits:
Testotron::Test show all
Defined in:
lib/tests/smtp.rb

Constant Summary collapse

KEY =
"smtp"

Instance Method Summary collapse

Constructor Details

#initialize(host, port = 25) ⇒ SMTP

Returns a new instance of SMTP.



8
9
10
# File 'lib/tests/smtp.rb', line 8

def initialize(host, port = 25)
	@host, @port = host, port
end

Instance Method Details

#human_nameObject



12
13
14
# File 'lib/tests/smtp.rb', line 12

def human_name
	"SMTP test of #{@host}, port #{@port}"
end

#run(runner) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/tests/smtp.rb', line 16

def run(runner)
	runner.report self, "Testing SMTP server of #{@host} port #{@port}..."
	smtp = Net::SMTP.new(@host, @port)
	smtp.read_timeout = 2
	smtp.open_timeout = 2
	begin
		smtp.start
		smtp.finish
	rescue Errno::ECONNREFUSED => e
		raise TestFailed, "Server refused SMTP connection"
	rescue EOFError => e
		raise TestFailed, "EOF reached while connecting to SMTP server"
	rescue Exception
		raise TestFailed
	end
end