use Test; ... use My::Module; use Test::Resub qw(resub); use IO::Socket::INET; # test open_socket_to { my $rs = resub 'IO::Socket::INET::new', sub { 'a socket' }, capture => 1; my $socket = My::Module->open_socket_to( machine => 'example.com', port => '-29', ); # return value of ->open_socket_to is whatever IO::Socket::INET::new gives us ok( $socket, 'a socket' ); # We created the socket correctly - the fact that we provided an # illegal PeerPort doesn't need to be handled by this test: # IO::Socket::INET should have his own tests for his ->new. is_deeply( $rs->named_method_args, [{ PeerAddr => 'example.com', PeerPort => -29, Proto => 'tcp', Type => SOCK_STREAM, }] ); }