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.

  1. 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).

  2. 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.”
  3. 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.
  4. 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.
  5. Make sure you have RubyGems installed by running gem -v on a command line. RubyGems is the package manager for Ruby and should come with the standard Ruby installation.
  6. Run gem install cucumber to download and install Cucumber. Run cucumber --help to confirm that it worked.
  7. 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, cd to 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.
  8. Run gem install capybara to download and install the Capybara web automation library.
  9. Run gem install rspec to download and install a nice library for readable assertions (among other things).
  10. You’ll want Firefox with the Firebug plugin to do UI-related tests. If you haven’t already, install those.
  11. 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.
  12. 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 dir or ls there, you should see a “features” folder). Run cucumber, and you should see all the tests run and pass.

Related posts:

  1. The Latest on Cuke4Nuke
  2. How to Remove Duplication in Cucumber Tests Using Scenario Outlines
  3. Cuke4Nuke: Cucumber for .NET Teams
  4. Just Enough Regular Expressions for Cucumber
  5. Public ATDD with Cucumber Course, March 7-8, Denver (Postponed)

8 thoughts on “Getting Started with Ruby, Cucumber, and Capybara on Windows

  1. Hi,

    This is a great posting and very explanatory. However the purpose i was reading through it from the subject is not explained here. I was looking for something to know, how can i test my windows application with cucumber and Ruby.

    Maybe as i am new to, i might not have understood most., but is it possible to explain it in detail. On can we test Windows based application using Ruby and cucumber.

    Thanks,
    Vimal

    • @Vimal – This post is about testing a web application from Windows using Ruby. I’m not sure what Windows application drivers are available in Ruby, though a quick search turned up win32-autogui. You might try that in place of Capybara.

  2. I got a Timeout error:
    [code]
    Feature: Demo
    Make sure Cucumber and Capybara are wired up properly

    Scenario: Search Google # featuresdemo.feature:4
    When I search Google for "cucumber" # features/step_definitions/demo_steps.rb:1
    Timeout::Error (Timeout::Error)
    C:/Ruby192/lib/ruby/1.9.1/net/protocol.rb:140:in `rescue in rbuf_fill'
    C:/Ruby192/lib/ruby/1.9.1/net/protocol.rb:134:in `rbuf_fill'
    C:/Ruby192/lib/ruby/1.9.1/net/protocol.rb:116:in `readuntil'
    C:/Ruby192/lib/ruby/1.9.1/net/protocol.rb:126:in `readline'
    C:/Ruby192/lib/ruby/1.9.1/net/http.rb:2219:in `read_status_line'
    C:/Ruby192/lib/ruby/1.9.1/net/http.rb:2208:in `read_new'
    C:/Ruby192/lib/ruby/1.9.1/net/http.rb:1191:in `transport_request'
    C:/Ruby192/lib/ruby/1.9.1/net/http.rb:1177:in `request'
    C:/Ruby192/lib/ruby/1.9.1/net/http.rb:1170:in `block in request'
    C:/Ruby192/lib/ruby/1.9.1/net/http.rb:627:in `start'
    C:/Ruby192/lib/ruby/1.9.1/net/http.rb:1168:in `request'
    ./features/step_definitions/demo_steps.rb:2:in `/^I search Google for "(.*)"$/'
    featuresdemo.feature:5:in `When I search Google for "cucumber"'
    Then there should be a result for "cukes.info/" # features/step_definitions/demo_steps.rb:7

    Failing Scenarios:
    cucumber featuresdemo.feature:4 # Scenario: Search Google

    1 scenario (1 failed)
    2 steps (1 failed, 1 skipped)
    1m19.597s
    [/code]
    on Windows XP, SP3, behind a proxy,
    RubyGems Environment:
    – RUBYGEMS VERSION: 1.7.2
    – RUBY VERSION: 1.9.2 (2011-07-09 patchlevel 290) [i386-mingw32]
    – INSTALLATION DIRECTORY: C:/Ruby192/lib/ruby/gems/1.9.1
    – RUBY EXECUTABLE: C:/Ruby192/bin/ruby.exe
    – EXECUTABLE DIRECTORY: C:/Ruby192/bin
    – RUBYGEMS PLATFORMS:
    – ruby
    – x86-mingw32
    – GEM PATHS:
    – C:/Ruby192/lib/ruby/gems/1.9.1
    – U:/.gem/ruby/1.9.1
    – GEM CONFIGURATION:
    – :update_sources => true
    – :verbose => true
    – :benchmark => false
    – :backtrace => false
    – :bulk_threshold => 1000
    – REMOTE SOURCES:
    http://rubygems.org/
    - cucumber version : 1.7.2

    • @Serguei – Your timeout seems be related to your proxy. I haven’t tried Capybara with a proxy. It’s using Net::Http under the covers (as you can see from the stack trace). I’d suggest searching for “ruby net http proxy” or something similar to see what you can turn up. Or, post your question to the Capybara Google group.

  3. You should download a zip file ‘ansi150.zip’ from: https://github.com/adoxa/ansicon/downloads. Unzip it somewhere and you will get a folder that contains x64, x86 folders and some C files. Inside of ‘x86′ folder you will find a ‘ansicon.exe’ file to be executed. You can later create a shortcut on your desktop pointing to it.

Leave a Reply

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

*

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>