Search⌘ K
AI Features

End-to-End Testing

Explore end-to-end testing in Rails using Capybara and RSpec to simulate real user interactions with your application. Learn outside-in testing to define features from the user's perspective and drive the design with supporting unit tests. Understand how to set up Capybara and write tests that fill forms, submit data, and verify visible outcomes without depending on code structure.

Outside-in testing

We’ll follow a testing practice called outside-in testing, which involves writing an end-to-end test that defines the feature (the “outside”) and augmenting it with a series of unit tests that drive the actual code and design (the “inside”).

Capybara

Capybara will make our end-to-end tests easier to read and write. It allows tests to describe user interaction with the web page and the document object model (DOM). We’ll cover Capybara and end-to-end testing in more detail in the chapter “Integration Testing with Capybara and Cucumber”.

Capybara installation

In Rails 5.1 and higher, Capybara is already included as part of the default project. In older projects, we add it to the Gemfile:

group :test do
  gem "capybara"
end

Then we reinstall the bundle:

$ bundle install

Capybara setup

Then to make two more system-setup tweaks that will be useful. First, in ...