Daniel Morrison

Helpful Cucumber Steps

There are a few Cucumber steps that have made their way into more and more of our projects. I thought I’d share for fun.

WTF Steps

These are simple wrappers for things you can already do easily with Cucumber, but instead of having to toss them in individual steps, you can toss them right in the feature when you’re trying to see what’s going on.

<pre> Given some setup stuff When i go to a troublesome page And I see wtf is going on Then the result is good </pre>

Time Steps

If you need to do anything with time, time zones, or whatever, Timecop is your new best friend.

I started using it on an app we were developing where I had two parties, potentially in different time zones, scheduling appointments with each other. I wanted to test in a few places that they were getting reminders at the right time, seeing the correct time in those reminder emails1, etc.

The first let’s you set the current time quickly. For example,

<pre> Given the time is 10:00 UTC </pre>

This was great for my emails where I wanted to know that it was showing the right time to the user. I did this, then checked that the time was 5 am for my user in Detroit:

<pre> And the time is Jan 1 2010, 10:00 UTC </pre>

The time passing step is great when you need to do things that are scheduled in the future. For my reminder example, an appointment reminder is sent 24 hours before the event. Here’s what I do in my features:

<pre> Given an appointment between "Bob" and "Sue" in 2 days When 25 hours pass Then an email is sent to "Bob"... </pre>

Enjoy!

1 I found my emails were wrong. I was setting Time.zone in the mailer, and outputting times in the body. I found I had to explicitly call .in_time_zone in the mailer view, which I hadn’t expected. Yay tests!

1 Comment

  1. Munna vikram — April 07, 2020

    This game needs a creative mind, there is a multiplayer game in just as a single game. robux generator So visit here and download the Roblox game.