Getting Started with Ruby, Cucumber, and Capybara on Windows
The Ruby version of Cucumber isn’t just for Rails developers. If you have a .NET or Java web or service app, Ruby can be a great language for testing. With libraries like Capybara for driving web apps and JSON, RestClient, SOAP, and others for interacting with service apps, you’ll find testing in Ruby requires much less code than in C# or Java.
It can be hard to find instructions for setting up Ruby and Cucumber on Windows, though, so I’ve compiled these to help my clients get started, and I thought they might be useful to others. I’ve tested this on a clean Windows 7 VM, and everything works. Your mileage may vary, but let me know if you have any issues.
- You’re going to be working in a command window quite a bit with Cucumber. You may want to customize your command window to make it more pleasant to use. I like the following settings (right click on the top left corner of the command window and choose Properties to set these):
Font: Consolas, 20pt
Screen Buffer: 120×3000
Window Size: 120×60
On a smaller screen, you’ll of course want a smaller window size and screen buffer. If you’re on an earlier version of Windows, you won’t be able to choose Consolas for the font, but Lucida Console is still better than the default.
I also like to set a PROMPT environment variable to
$P$_$+$G(right click on My Computer and choose Properties, then Advanced, then Environment Variables).
- Download and install Ruby. For Windows, http://rubyinstaller.org/ is the best option. Install the latest release of version 1.9.2. Make sure you check the option to “Add Ruby executables to your PATH.”
- Also install the Ruby Development Kit from the same place, which will allow Ruby to build native extensions for libraries. Instructions are available here: https://github.com/oneclick/rubyinstaller/wiki/Development-Kit.
- Confirm that the installation worked by opening a command window and running
ruby -v. You should see a description of the Ruby version installed. If you see an error, something went wrong with the installation.
- Make sure you have RubyGems installed by running
gem -von a command line. RubyGems is the package manager for Ruby and should come with the standard Ruby installation.
gem install cucumberto download and install Cucumber. Run
cucumber --helpto confirm that it worked.
- Cucumber complains that you need ANSICON to get console colors because Windows doesn’t understand ANSI color escape sequences. Download ANSICON from http://adoxa.3eeweb.com/ansicon/. Extract it somewhere (I put it in c:utils). In your command window,
cdto either the x86 or x64 directory where you extracted ANSICON, depending on your OS, and run
ansicon -i. Exit that command window and open a new one. Now, when you run
cucumber --help, you should no longer see the message in the output about needing ANSICON.
gem install capybarato download and install the Capybara web automation library.
gem install rspecto download and install a nice library for readable assertions (among other things).
- You’ll want Firefox with the Firebug plugin to do UI-related tests. If you haven’t already, install those.
- You can edit Cucumber tests and automation code in Notepad, Visual Studio, or any other text editor. But I like having an editor that knows about Cucumber and provides Cucumber-oriented features, so I use JetBrains RubyMine to work with my Cucumber tests. There’s a free 30 day trial available.
- To make sure Cucumber and Capybara are working nicely together, download and extract this Ruby, Cucumber, and Capybara Starter Project somewhere on your machine. Open a command window at the root of the folder (if you run
lsthere, you should see a “features” folder). Run
cucumber, and you should see all the tests run and pass.
Update 4/15/2013 — Blog comments aren’t a good place to answer detailed technical questions, so I’ve closed commenting on this post. I encourage you to use the Cucumber and Capybara Google Groups if you run into problems.