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.

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.

Related Articles

Responses

  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

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

    1. @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. I downloaded ansicon from Github, but there is no executable in it. CMD does not recognizes the ansicon command.

  4. 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.

  5. Mr Richard Lawrence , you have save me from countless hours of trying to get cucumber working on my system ,i am very grateful to you for putting up this tutorial

  6. When I attempted to run the command “gem install cucumber”, I obtained the below error:
    Error: Error installing cucumber:
    ERROR: Failed to build gem native extension.
    C:/Ruby187/bin/ruby.exe extconf.rb creating Makefile
    make
    ‘make’ is not recognized as an internal or external command, operable program or batch file.

    I am using Windows7.

    1. @Allison – Did you install the DevKit mentioned in step 3? Your error looks like the tools to compile a C extension are missing.

      1. Thank you Richard for your prompt response. I did omit extracting the files in the DevKit. I have now successfully installed cucumber.

  7. Very easy to follow and clear instructions. You’re page has saved me numerous hours of searching for details on Ruby and Cucumber set up for Windows.

    Many thanks.

  8. I’m getting a 404 error on the link: Ruby, Cucumber, and Capybara Starter Project.
    It would be great to look at the project

    1. @Oliver – Not sure why that file was missing, but I’ve uploaded it again, and it seems to work now. Thanks for letting me know.

  9. Any suggestions for a free IDE for Ruby + Cucumber than JetBrains RubyMine

        1. I use “Sublime Text 2” it’s not free, but it’s free to try for an unlimited amount of time. It’s also not as sophisticated as Aptana Studio or RubyMine, but I like it a lot because it still has auto complete for functions/variablenames, etc…

  10. I have the following error: Ruby on Rails – error when running cucumber: You have already activated activesupport 3.2.8, but your Gemfile requires activesupport 3.1.0.

    any one can help

  11. Nice tutorial but can you explain what all those files in side the ruby-capybara do ?
    like inside the .idea folder and so on. how to they link to other components, which files are necessary for the project to run. How do you actually build a project form scratch.

    Thanks

  12. Brilliant! many thanks…

    I’m a newbie who has run into some capybara-webkit issues who truly appreciates the help in proving I can establish some functionality in my windows7 environment.

    I ran your cucumber test. The 1 scenario and the 2 steps all passed. Firefox window launched, ran the test, and then shut down as quickly.

    One (two) question(s): Is the following error message expected? Or does it suggest I still have a configuration issue?
    !!! error running onStopped callback: TypeError: callback is not a function
    *** LOG addons.xpi: shutdown

  13. Richard –

    THANK YOU!!! You didn’t miss a step. I cannot tell you how frustrated I get by the amazing amount of omissions people tend to have in this kind of instruction. Yours were flawless.

    I do have one question though. I get 1 scenario (i passed) then, 2 steps (2 passed) but then…
    !!! error running onStopped callback: TypeError: callback is not a function…

    do you get this error?

    1. @trevor – This looks like an issue between Selenium and Firefox. The capybara Google group would be your best place to get a specific answer on what to do about it.

  14. Thanks a lot for this Richard. I got the project set up nicely and the tests run fine. But I am also getting the same error mentioned by trevor i.e.

    “!!! error running onStopped callback: TypeError: callback is not a function…”

    I get this after the execution is finished.

  15. I am getting following message: Not sure what I am doing wrong. Everything installed fine.

    C:Ruby187bin>cucumber
    Feature: Demo
    Make sure Cucumber and Capybara are wired up properly

    Scenario: Search Google # featuresdemo.feature:4
    When I search Google for “cucumber” # featuresdemo.feature:5
    Then there should be a result for “cukes.info/” # featuresdemo.feature:6

    1 scenario (1 undefined)
    2 steps (2 undefined)
    0m0.025s

    You can implement step definitions for undefined steps with these snippets:

    When(/^I search Google for “(.*?)”$/) do |arg1|
    pending # express the regexp above with the code you wish you had
    end

    Then(/^there should be a result for “(.*?)”$/) do |arg1|
    pending # express the regexp above with the code you wish you had
    end

    If you want snippets in a different programming language,
    just make sure a file with the appropriate file extension
    exists where cucumber looks for step definitions.

    1. @Yamini – That’s Cucumber not being able to find the Ruby step definitions. They should be under features/step_definitions from your working directory. Are they?

  16. HI

    I am new using ruby and cucumber. I installed ruby and all the gem files etc. however, I do not know how to use cucumber. Can you please guide me. I appreciate your help. Thanks.

    1. HI

      Thanks for your response. I have all these under features/step definitions in my C: directory. However, when I type in to the command prompt it comes back as project folder not found. Can you please help me. thanks.

  17. Great help. Thanks much! FYI – I was getting a “stack level too deep (SystemStackError)” at gherkin_builder.rb:100, but when I switched from Ruby 2.0.0 to 1.9.3 the problem went away.

  18. HI

    I created a features directory and ran cucumber and I am getting0scenarios, 0 steps and 0m0.000…After this what do I need to enter in the command to create or adding a scenario. I am new to cucumber. I am learning. I have not used command. Please help me with the commands that I can enter in order to set up a scenario to get fail and pass results. I appreciate your help.
    If I type features/adding.feature: I am getting an error saying feature is not recognized as an internal or external command operable program or batch file error.

    1. @sudha – Try using the starter project in step 12 above, which will give you all the pieces you need. You might also check out the Cucumber website, which has links to tutorials and other documentation.

Comments are closed.