Recipe 13Manipulate Time

Problem

You want to test a long-running process, but you don’t want your tests to be slow.

Ingredients

  • Capybara[87] for testing web apps in multiple ways, both headless and in-browser

  • Timecop[88] for faking the time of day in Ruby

  • Sinatra[89] for building the sample app

Solution

One of the biggest time sinks in testing is waiting on your app. Whenever a program has to connect to a slow network, make a lengthy calculation, or wait for a specific time of day, you can speed up your tests dramatically by finding a way around the delay.

In this recipe, we’re going to write a simple web app that has a fixed delay built in. We’ll start with a slow test that waits for the app to finish its task. We’ll then look at a couple of ...

Get Cucumber Recipes now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.