Contents

Yes Mum, still behaving

Contents

In a previous post I talked about using Cucumber and Cucumber- Nagios to do what I crudely called “Behaviour Driven Infrastructure”. In that post I gave you a very brief introduction to Cucumber’s syntax. This post explores another piece of syntax called outlining that allows you to shortcut some of your testing scenarios. In the tests we demonstrated you could potentially end up with some quite repetitive scenarios, for example:

  Scenario: Visiting home page
    When I go to http://www.google.com
    Then the request should succeed

If we have multiple websites we can end up with repetitive scenarios like:

  Scenario: Visiting home page
    When I go to http://www.google.com
    Then the request should succeed
  Scenario: Visiting home page
    When I go to http://www.nextsite.com
    Then the request should succeed
  Scenario: Visiting home page
    When I go to http://www.anothersite.com
    Then the request should succeed

We can summarise this series of scenarios with a nifty bit of refactoring using some Gherkin (Cucumber’s DSL) syntax called an Outline. Using an outline we can create a kind of template like so:

Scenario Outline: Home
  When I go to <url>
  Then the request should succeed
  Examples:
  | url                   |
  | http://www.google.com |
  | http://www.nextsite.com |
  | http://www.nextsite.com |

Cucumber turns each example - each table row - into a concrete scenario before looking for matching step definitions. And hey presto when it runs you get:

$ bin/cucumber --require features/ features/home/outline.feature
Scenario Outline: Home          # features/home/outline2.feature:1
When I go to <url>              # features/steps/webrat_steps.rb:1
Then the request should succeed # features/steps/result_steps.rb:13

Examples:
| url                     |
| http://www.google.com   |
| http://www.nextsite.com |
| http://www.nextsite.com |

3 scenarios (3 passed)
6 steps (6 passed)
0m3.123s

Update - you need cucumber-nagios version 0.7.2 later to use outlines…