Testing a Sample Cucumber Feature Using Ruby

There are a few examples I have found online, but it took quite a while for me to get all the information I needed to actually make this work. So here is everything that I was able to find to get Cucumber up and running.

Start by creating a new folder for the project. Doesn’t really matter where you put this folder, but try keep things organised. Create a new folder called features and inside make a “sample”.feature file that contains the feature which is just a simple description

Here is the most common sample that has been floating around the web.


So the first thing you can do is attempt to run this file. You should get back errors, but at least you now know that everything is set-up and working correctly.

Cucumber sample.feature

This will give back 4 errors because the steps for this have not been implemented yet. Copy and paste the suggested empty stubs that cucumber returns and paste them into a .rb file. If you are using a standard windows command shell, you can right click on the window and click “mark”. This allows you to highlight text in the command shell window. This file needs to be put inside a folder called step_definitions. eg. myproject/features/step_definitions/steps.rb

Rerun the same feature and the result will be different. It should give an error for the first step telling you there has been no code implemented and then it will skip the rest of the tests.

Go back to the steps.rb file and now you can add some ruby code to the stubs that will successfully do what was described in the above scenario. Once this code has been added all of the codes will pass and uoi will be looking at a nice screen of green.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.