Running Our Program

To implement the next step, edit features/step_definitions/calculator_steps.rb so that the second step definition looks like this:

 When(​/^the calculator is run$/​) ​do
  @output = ​`ruby calc.rb ​​#{​@input​}​​`
 raise​(​'Command failed!'​) ​unless​ $?.success?
 end

This code attempts to run our calculator program calc.rb, passing it the input we stored in the first step and storing any output in another instance variable. Then it checks a specially—but rather cryptically—named Ruby variable $? to check whether the command succeeded and raises an error if it didn’t. Remember that Cucumber fails a step if the step definition raises an error; this is the ...

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.