You are previewing Test-Driven Infrastructure with Chef.

Test-Driven Infrastructure with Chef

Cover of Test-Driven Infrastructure with Chef by Stephen Nelson-Smith Published by O'Reilly Media, Inc.
O'Reilly logo

Writing Acceptance Tests

You now start to convert the requirements you identified into acceptance tests. At this stage you’re actually using the Gherkin language, which consists of fewer than a dozen key words and a few pieces of punctuation. The best (and easiest to read) documentation for the Gherkin language is at the Behat project, so for more detail, please refer to

Given, When, and Then[24] are Gherkin keywords, but for the purposes of writing the acceptance test, they are used to describe the context in which an event will happen, and then describe the expected outcome.

Now, at this point, it’s necessary to understand the connection between the Cucumber feature and the other two aspects of Cucumber—the command itself, and the step definitions.

Step definitions are methods written in a high-level programming language which set up the scenarios, and perform various tests to determine whether the resulting state matches the intended state. At the time of writing, there are at least eight supported languages for writing step definitions. We’re going to be using Ruby. The steps in the scenario map directly to the step definitions. Here’s a trivial example:

Given an adding machine
When I input the numbers "1" "2" "3"
Then the answer should be "6"

The matching step definitions might say:

Given /^an adding machine$/ do machine = end When /^I input the numbers "([^"]*)" "([^"]*)" "([^"]*)"$/ do |arg1, arg2, arg3| answer = machine.add(arg1, ...

The best content for your career. Discover unlimited learning on demand for around $1/day.