...

/

Running Tests: Configuring RSpec

Running Tests: Configuring RSpec

Learn to configure RSpec for tests that rely on JavaScript.

Configuring RSpec system tests

We have created a new Capybara driver, but how do we configure RSpec to use it?

First, we have to edit spec/rails_helper.rb to require our new Capybara driver so that it is loaded:

Press + to interact
require 'rspec/rails'
# Add additional requires below this line. Rails is not loaded until this...
require_relative './support/capybara.rb'

Often apps will auto-require all .rb files inside the spec/support directory. If that is the case for your app, this require could be omitted.

Making it work for non-JavaScript system tests

OK, what next? Recall that earlier, we used RSpec’s configuration hooks to set rack_test as the default driver for our system tests. We now need to make it so that non-JavaScript system tests continue to use that, whereas JavaScript tests (indicated with the js: true tag in the test definition) should use our new Selenium Chrome Capybara driver.

We can achieve this by adding the following lines to ...