My Rails app is using the net sftp gem to connect to a third party server and retrieve files there. The problem is, they will block the connection if we attempt to connect too many times consecutively. Our code retrieves the file once a day at 4:00AM so that's normally not an issue.
But we do have code to test if the retrieved files are parsed correctly, and when we run our tests too many times in a row, the SFTP server will block us out, so another developer on our team cannot work on another feature that needs to connect to the SFTP server anymore. Normally, we stub out the SFTP request, but we recently found out someone forgot to add the stub in one of the tests, so we always get a connection refuse for the past couple days because another one of us is trying to fix some tests and they run the test suites a bunch of times in a row.
Our stub looks like this:
sftp_start = mock
empty_extract = file_fixture("fixture_csv.csv").read
sftp_start.stubs(:download!).returns(empty_extract)
Net::SFTP.stubs(:start).yields(sftp_start)
So, the question is, is there a way to block SFTP connections in the test environment, so if someone did forget to add the stub, we'd get an error instead? I know webmock can block external requests, but it doesn't seem to catch SFTP requests. I did some googling but didn't find anything related to this issue so any suggestions would be nice! We are using minitest to run our tests.