Plugin histories

Webrat: Ruby acceptance testing before Capybara

Plugin histories · · Published 2026-10-24

An old beige CRT monitor and keyboard in a dark room, the screen glowing
An old CRT monitor and keyboard glowing in a dark room.

Before Capybara and Rails system tests, Webrat was how many Rails developers wrote tests that clicked through their application like a user. It shaped the vocabulary still used today, then quietly stopped being developed.

What Webrat did

Webrat added a browser-like API to Rails integration tests. Instead of constructing HTTP requests by hand, you described what a user would do:

visit "/signup"
fill_in "Email", with: "ada@example.com"
fill_in "Password", with: "correct horse"
click_button "Create account"
assert_contain "Welcome"

Behind the scenes, Webrat parsed the returned HTML, found the form fields by their labels, names or ids, and submitted the form with the right parameters, all inside the Ruby process. There was no real browser, so tests were fast and needed nothing installed beyond Ruby. When JavaScript had to run, Webrat offered a Selenium mode that drove a real browser through the same API, plus adapters for Merb, Sinatra and Mechanize.

Webrat became a cornerstone of behaviour-driven development in Ruby. Cucumber's generated step definitions for Rails originally used it, which is why phrases such as When I fill in "Email" with "..." and And I press "Sign in" appear in so many old feature files.

Status

The Webrat repository belongs to GitHub user brynary. According to RubyGems.org, its last release is 0.7.3, published on 2 January 2011, and it never reached 1.0. It did not follow Rails beyond the 3.0 era, and its dependencies target Ruby versions long out of support. Webrat should not be used in any current application.

Why Capybara replaced it

Capybara appeared in 2009 with an API intentionally close to Webrat's, but with a different architecture: a single DSL on top of interchangeable drivers. The same test could run against Rack::Test (fast, no JavaScript), Selenium with a real browser, or other headless drivers, by changing one setting. Capybara also introduced automatic waiting for asynchronous content, which became essential as applications relied more on JavaScript. Cucumber's Rails integration switched to Capybara, and the community followed.

Rails itself adopted Capybara: system tests, added in Rails 5.1, are built on it, and the Rails generators create them for you. The system testing section of the Rails testing guide describes the current setup.

Migrating Webrat tests

Most Webrat steps translate directly; the main differences are in assertions and in scoping:

WebratCapybara
visit pathvisit path
fill_in "Email", with: "..."fill_in "Email", with: "..."
click_button "Save"click_button "Save" or click_on "Save"
click_link "Edit"click_link "Edit"
select "France", from: "Country"select "France", from: "Country"
check "Terms"check "Terms"
assert_contain "Saved" / response.should contain("Saved")assert_text "Saved" / expect(page).to have_content("Saved")
within "#sidebar" do ... endwithin "#sidebar" do ... end
response.bodypage.html

A few habits need attention during migration:

Choosing a driver today

Rails system tests default to Selenium with a headless Chrome browser. Alternatives include Rack::Test for pages without JavaScript, which is the closest equivalent to Webrat's in-process approach and the fastest option, and Cuprite, which drives Chrome directly through the DevTools protocol without a separate WebDriver binary. Many teams use Rack::Test by default and switch to a browser driver only for tests tagged as needing JavaScript.

Legacy

Webrat's lasting contribution is its vocabulary. visit, fill_in, click_button and within survive almost unchanged in Capybara and therefore in every Rails system test written today. For the rest of the modern testing toolbox, see our guide to testing Rails applications.