@@ -59,6 +59,7 @@ def test_list_of_hosts_with_all_hosts_failure
59
59
end
60
60
end
61
61
62
+ # This belongs in test_ldap, not test_ldap_connection
62
63
def test_result_for_connection_failed_is_set
63
64
flexmock ( TCPSocket ) . should_receive ( :new ) . and_raise ( Errno ::ECONNREFUSED )
64
65
@@ -73,33 +74,36 @@ def test_result_for_connection_failed_is_set
73
74
end
74
75
75
76
def test_unresponsive_host
77
+ connection = Net ::LDAP ::Connection . new ( :host => "fail.Errno::ETIMEDOUT" , :port => 636 )
78
+ connection . socket_class = FakeTCPSocket
76
79
assert_raise Net ::LDAP ::Error do
77
- Net :: LDAP :: Connection . new ( :host => 'test.mocked.com' , :port => 636 )
80
+ connection . socket
78
81
end
79
82
end
80
83
81
84
def test_blocked_port
82
- flexmock ( TCPSocket ) . should_receive ( :new ) . and_raise ( SocketError )
85
+ connection = Net ::LDAP ::Connection . new ( :host => "fail.SocketError" , :port => 636 )
86
+ connection . socket_class = FakeTCPSocket
83
87
assert_raise Net ::LDAP ::Error do
84
- Net :: LDAP :: Connection . new ( :host => 'test.mocked.com' , :port => 636 )
88
+ connection . socket
85
89
end
86
90
end
87
91
88
92
def test_connection_refused
89
- flexmock ( TCPSocket ) . should_receive ( :new ) . and_raise ( Errno ::ECONNREFUSED )
93
+ connection = Net ::LDAP ::Connection . new ( :host => "fail.Errno::ECONNREFUSED" , :port => 636 )
94
+ connection . socket_class = FakeTCPSocket
90
95
stderr = capture_stderr do
91
96
assert_raise Net ::LDAP ::ConnectionRefusedError do
92
- Net :: LDAP :: Connection . new ( :host => 'test.mocked.com' , :port => 636 )
97
+ connection . socket
93
98
end
94
99
end
95
100
assert_equal ( "Deprecation warning: Net::LDAP::ConnectionRefused will be deprecated. Use Errno::ECONNREFUSED instead.\n " , stderr )
96
101
end
97
102
98
103
def test_raises_unknown_exceptions
99
- error = Class . new ( StandardError )
100
- flexmock ( TCPSocket ) . should_receive ( :new ) . and_raise ( error )
101
- assert_raise error do
102
- Net ::LDAP ::Connection . new ( :host => 'test.mocked.com' , :port => 636 )
104
+ connection = Net ::LDAP ::Connection . new ( :host => "fail.StandardError" , :port => 636 )
105
+ assert_raise Net ::LDAP ::Error do
106
+ connection . socket
103
107
end
104
108
end
105
109
0 commit comments