Learn how to run Cucumber on Rake to lead your agile testing team down the path to automation.
Blog seven of a series.
Created by Jim Weinrich quite a few years ago, Rake is “a Make-like program implemented in Ruby.”
For those of you unfamiliar with JAVA, “Make in Java (jmk) is an application that is used to ensure a set of files is in a consistent state. If jmk detects an inconsistency, it executes commands that correct the inconsistency.”
We still haven’t even highlighted the best part of the Rake file. Rake does in Ruby what Make does in JAVA: It ensures files are in a consistent state. Then it executes the task you specify.
This is a huge benefit because it ensures you don’t make any formatting mistakes in Feature files, or insert typographical errors in a step definition.
If there are inconsistencies, you’ll catch them by running Cucumber using Rake.
Cucumber took advantage of the power of Rake to help you create cucumber rake tasks. Setting these up is simple. In the Rake file, you need to require ‘cucumber’ and ‘cucumber/rake/task’.
See the results in the following cucumber rake task:
Below is the format of the cucumber rake task:
First, Cucumber takes advantage of Rakes’ Task.new. This is where you create a new Rake task to execute. You can extend this to create a new Rake task specific to Cucumber. The :task name can be any unique name you wish to name the task. More on this in a minute.
Lastly, the Cucumber profile will determine which profile in the cucumber.yml file this specific task will use. The cucumber.yml file extends the command line for you. The format is simple: cucumber_profile: parameters
The cucumber profile then ties to the cucumber rake task. Parameters can control anything from the format cucumber will use to where the output is sent to. An example of the default profile: –no-source –color –format pretty
Running with Rake
Rake is executed from the command line. The format is simple: rake <task name>
The task name is specified in Cucumber::Rake::Task.new(:task name). After you hit enter, Cucumber will go through every Cucumber Rake task looking for the specific task name you passed. Once found, it will execute.
A WebDriver Example
In future blog articles, we will build a WATiR-WebDriver-based Cucumber automation framework. In the blog about tags, we will set-up our Feature file with tags so it can be easily executed by Rake:
For rake to execute this, we first need to set-up the cucumber.yml file like this:
Next, set-up the Cucumber Rake Task:
All that is left now is to open a command prompt and type: rake webdriver_search. Cucumber should launch and you should see an all pass. To run this via RubyMine go to Tools -> Run Rake Task:
You will be presented with a list of all the Rake tasks you currently have. Note: you might have to reload rake tasks lists:
Select webdriver_search and watch it run.
Rake can be an extremely powerful tool. Mastering its nuances will enable you to control your output, manage reports much cleaner, and run your jobs in a Continuous Integration (CI) environment.