O'Reilly logo

Rails 4 Test Prescriptions by Noel Rappin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Setting Up Capybara

Capybara allows an automated test to simulate a user interaction with a browser. When simulating this interaction, Capybara works in conjunction with a driver, using the simple Capybara API to determine what elements to interact with and using the driver to manage the actual interaction. By default Capybara uses a native Ruby library that doesn’t manage JavaScript interactions, but it can be configured to use a headless browser such as PhantomJS or Selenium to allow JavaScript interactions to be simulated.

Capybara and RSpec

Capybara is designed for use with RSpec, and if you want to use them together, add Capybara to your Gemfile’s testing group:

 
gem "capybara"

You also need to add the following line to your rails_helper.rb ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required