Implementing Our First Step Definition

We’ve decided this first release of our calculator is going to take its input from the user as a command-line argument, so our job in the step definition for Given the input "2+2" is just to remember the input so that we know what to pass on the command line when we run the calculator in the next step. In the features/step_definitions folder, edit the calculator_steps.rb file so that the first step definition looks like this:

 Given(​/^the input "([^"]*)"$/​) ​do​ |input|
  @input = input
 end

All we’ve done here is store the input from the feature in a Ruby instance variable. That instance variable will be around for as long as this particular ...

Get The Cucumber Book, 2nd Edition 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.