Speed up your BDD with Sublime Text 2

Abstract

As far as I remember, We had London Behat User’s meetup at SkillsMatter, London on 23, May 2012 titled “Speed up your BDD with Sublime Text 2

Christophe Willemsen [@ikwattro] came to London all the way from Belgium to present Behat/Mink Snippets he worked on. Here is  Github repository.  Now these snippets are part of Package Controller of the Sublime Text 2. I would like to thank him for his awesome work. In this short tutorial, I will try to explain his work on Behat snippets for Sublime Text 2 and use of Gherkin syntax.

BDD & Feature Files

The key benefit of the Behavior Driven Development [BDD] is to bridge communication gap by writing human readable specifications. In the language of BDD, these specifications are often written in Domain Specific languages like Gherkin. Well written feature files are the building blocks of the BDD project.

Here are some common problems usually faced by teams [Developers, QA, Business]  in writing feature files:

  • Not familiar with Gherkin syntax.
  • Don’t know how to use ‘Example Tables’ in the scenarios.
  • Don’t know how & when to use “Given, When, Then, And, But” statements. [Mixing of GWT]
  • Don’t know how to write reusable steps using Gherkin.

This problems can be avoided by using perfect text editor like “Sublime Text 2

Sublime Text 2

Sublime text is a perfect editor for writing feature files in the BDD projects, having said that I have tried couple of editors and compared to them Sublime Text 2 worked way better.

I have used NetBeans for long time, It was working well with Cucumber plugin as it can format your feature files easily, create template feature files, Gherkin syntax highlighting, error reporting in case of wrong Gherkin syntax etc etc. Looks Good. There are couple of thing which annoyed me a lot about NetBeans. NetBeans Cucumber plugin crashes whenever it wish to and once it crashed you have to restart NetBeans which is too slow to kick off.

I also tried ‘VIM‘ also spend enough time to learn about Vim and it’s plugins. Thanks God, I have came across this blog post just in time without spending more time to lean Vim rather than learning actual implementation techniques. Can’t argue that ‘Vim’ is awesome editor for Geeks but to me ‘Learning Tools & Technologies’ is more important than ‘Learning Editor’ at this point.

So, Sublime Text 2 is my best friend!!. You can download it from website . You can read awesomeness of Sublime Text 2 in the blog post ‘Tricks and Tips” by Net tuts+. Things I like about Sublime Text 2 are

  • Works On Mac OSX and Linux.
  • Lighting Fast while Editing and Switching Files from Command Palette.
  • Package Control which supports loads of plugins with easy installations. Thanks to Will Bond
  • How Can I forget ‘Multiple Cursors’ while editing ?
  • Supports ‘n’ number of  Languages.

Ok. enough description here. I would strongly recommend this Video in order to learn awesomenimity  of Sublime Text 2 and how it stand out from other editors.

Sublime Text with BDD Tools: Behat and Cucumber

I assume that you have installed Sublime Text 2 and downloaded Package Control plugin which is fairly easy and straightforward.

How to install Packages from Package Control. ?

  • Type ‘Command+Shift+P’ 
  • Start typing “package” in the command palette and it will show different options.
  • Select Install Packages & hit Enter

Now, Install following Packages to get started.

  •  Behat
  • Sublime-Behat-Snippet
  • Cucumber
  • Gherkin[Cucumber] Formatter

Start Writing Feature Files

Believe it or not you can write sample feature file within a minute. You may probably argue that NetBeans Cucumber plugin provide template feature file much easier but real power of sublime Text is it’s speed. Follow 3 steps and you will get Feature files within a minute.

1] Hit ‘Command + Shift + P’ & type ‘Gherkin‘. Hit Enter. It will set syntax to “Gherkin”
2] Hit ‘Command + Shift + P’ & type ‘feature‘. Hit Enter. This will create story format
3] Hit ‘Command + Shift + P’ & type ‘scenario‘ Or ‘Scenario Outline’ && Hit Enter. This will create Scenario
4] Hit ‘Command + Shift + P’ & type ‘example‘ && Hit Enter. This will create example table.

You will see feature file created like this:

feature File

InBuilt Mink API’s

If your are using Behat-Mink for UI automation then Sublime Text has huge benefit for you. You can access built in Mink API’s directly from the Sublime. List of Mink API’s can be found here . You can also refer behat-cheat-sheet to get help.

Bhehat-Mink : Given

You can type ‘given‘ in the command palette [ Command +Shift + P] and you will list of available options like this.

behat-given

 

 

Behat-Mink: When

You can type ‘when‘ in the command palette [ Command +Shift + P] and you will list of available options like this.

behat-when

Behat-Mink: Then

You can type ‘Then‘ in the command palette [ Command +Shift + P] and you will list of available options like this.

behat-then

 

Video Demo

Let’s Create Sample Feature File using Sublime Text. Watch this Video.

Conclusion

Writing BDD feature files become so easy by using Sublime Text and it’s packages like ‘Gherkin’, ‘Cucumber’ and ‘Behat’. You can write better feature files using full power of Sublime Text2 .

Happy BDD !!  

Leave a Reply

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

* Copy This Password *

* Type Or Paste Password Here *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>