How to block port using Ruby for testing purposes

This post is about using a port so that other applications will not be able to use it in test scenarios. For instance, you have some tests that uses a mock web service and you require the use of ranges of port numbers.

Ruby version

The ruby version for this post is

Of course, you require to install Ruby first which, unfortunately, is not covered here.

Ruby Codes