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 scenario is running, so we can use it again in the next step when we actually run the calculator.
Great, that was easy. Now, where were we again? Let’s ask cucumber:
| Feature: Adding |
| |
| Scenario: Add two numbers |
| Given the input "2+2" |
| When the calculator is run |
| TODO (Cucumber::Pending) |
| ./features/step_definitions/calculator_steps.rb:9 |
| features/adding.feature:5 |
| Then the output should be "4" |
| |
| 1 scenario (1 pending) |
| 3 steps (1 skipped, 1 pending, 1 passed) |
| 0m0.021s |
Yay! Our first step passed! The scenario is still marked as pending, of course, because we still have the other two steps to implement, but we’re starting to get somewhere.