Skip to content

Commit 259f18a

Browse files
committed
update tests
1 parent 9a2e26e commit 259f18a

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

test/test_ldap_connection.rb

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def test_list_of_hosts_with_all_hosts_failure
5959
end
6060
end
6161

62+
# This belongs in test_ldap, not test_ldap_connection
6263
def test_result_for_connection_failed_is_set
6364
flexmock(TCPSocket).should_receive(:new).and_raise(Errno::ECONNREFUSED)
6465

@@ -73,33 +74,36 @@ def test_result_for_connection_failed_is_set
7374
end
7475

7576
def test_unresponsive_host
77+
connection = Net::LDAP::Connection.new(:host => "fail.Errno::ETIMEDOUT", :port => 636)
78+
connection.socket_class = FakeTCPSocket
7679
assert_raise Net::LDAP::Error do
77-
Net::LDAP::Connection.new(:host => 'test.mocked.com', :port => 636)
80+
connection.socket
7881
end
7982
end
8083

8184
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
8387
assert_raise Net::LDAP::Error do
84-
Net::LDAP::Connection.new(:host => 'test.mocked.com', :port => 636)
88+
connection.socket
8589
end
8690
end
8791

8892
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
9095
stderr = capture_stderr do
9196
assert_raise Net::LDAP::ConnectionRefusedError do
92-
Net::LDAP::Connection.new(:host => 'test.mocked.com', :port => 636)
97+
connection.socket
9398
end
9499
end
95100
assert_equal("Deprecation warning: Net::LDAP::ConnectionRefused will be deprecated. Use Errno::ECONNREFUSED instead.\n", stderr)
96101
end
97102

98103
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
103107
end
104108
end
105109

0 commit comments

Comments
 (0)