Using Aruba’s Ruby DSL

Aruba’s step definitions are a great example of how step definitions should be written. Each of them is hardly ever more than a single line long, delegating all its work to Ruby methods in Aruba’s support layer module Aruba::API. We can call these methods directly from our own step definitions, removing an unnecessary layer of indirection in our code. Here’s how the features/step_definitions/calculator_steps.rb file looks with each of the Aruba step definitions translated to their underlying method calls:

command_line_applications/12/features/step_definitions/calculator_steps.rb
 
Given /^the input "([^"]*)"$/ ​do​ |input|
 
write_file ​'input.txt'​, input
 
end
 
When /^the calculator is run$/ ​do
 
run ​'calculator input.txt' ...

Get The Cucumber Book 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.