tests/test_unbind_reason.rb in eventmachine-maglev--1.0.0.beta.4 vs tests/test_unbind_reason.rb in eventmachine-maglev--1.0.0.rc.4
- old
+ new
@@ -1,9 +1,18 @@
require 'em_test_helper'
require 'socket'
class TestUnbindReason < Test::Unit::TestCase
+
+ class StubConnection < EM::Connection
+ attr_reader :error
+ def unbind(reason = nil)
+ @error = reason
+ EM.stop
+ end
+ end
+
def test_connect_timeout
error = nil
EM.run {
conn = EM.connect 'google.com', 81, Module.new{ |m|
m.send(:define_method, :unbind) do |reason|
@@ -11,11 +20,11 @@
EM.stop
end
}
conn.pending_connect_timeout = 0.1
}
- assert_equal error, Errno::ETIMEDOUT
+ assert_equal Errno::ETIMEDOUT, error
end
def test_connect_refused
error = nil
EM.run {
@@ -24,8 +33,16 @@
error = reason
EM.stop
end
}
}
- assert_equal error, Errno::ECONNREFUSED
+ assert_equal Errno::ECONNREFUSED, error
+ end
+
+ def test_optional_argument
+ conn = nil
+ EM.run {
+ conn = EM.connect '127.0.0.1', 12388, StubConnection
+ }
+ assert_equal Errno::ECONNREFUSED, conn.error
end
end