Day 11 - Run your tests with your wifi off

First, a warning: today’s exercise is likely to generate tasks for you that will take longer than 20 minutes to fix. This doesn’t mean something bad has happened, or that you’ve failed. Just file a ticket to remind you to complete the work later.

Today’s exercise: run your test suite with your internet connection disabled.

Turns out, it’s fairly easy to accidentally rely on an external service during test runs (I’ve done it many times). This won’t just make your test suite slow, but brittle.

Chances are, you’ll see a few cryptic failures when you try this.

In general, I recommend reaching for a tool like Webmock to fix issues like these.

As a bonus, Webmock has a setting to disable external web requests during test runs. If you attempt to make a connection to the outside world, you’ll get an exception. This will prevent you from writing internet-hitting tests in the future.

Give it a try and let us know how it goes.

1 Like

Harder to do when you develop over remote SSH :joy:

For Ruby code, we use VCR Cassettes, which can auto-suppress any HTTP(s) calls and send a warning to the console if it does so. We have zero such warnings :slight_smile:

WIth VCR, you would then perform the remote call for real once, and record it. IMHO, a safer method than stubbing the HTTP library.

Darn, I thought I’d be good for this one!

My test suite runs fine without internet. Including the system tests.

But my CI build re-runs my database seeds. I have this in place to make sure nothing breaks for someone new to the project.

The seeds rely on downloading avatars from the network! This might take a while to fix.

Does anyone else do this? I’m open to suggestions or ideas. :slight_smile: