---
title: Migrating from feature specs to system specs
teaser: |-
  Rails supports writing Capybara tests out of the box since the 5.1 release in the form of system tests. This means you no longer need to configure database cleaning strategies or have webdriver configuration files with hard-to-understand configuration settings.
  This article explores how to migrate Feature specs in an existing Rails app to the default System specs.
tags: ruby on rails,rspec,capybara
author: Trésor Bireke
published_on: 2024-05-29
---

Rails supports writing Capybara tests out of the box since the 5.1 release in the form of system tests. This means you don't need to configure database cleaning strategies or have a separate webdriver configuration file with hard-to-understand configuration settings, or other verbose capybara/selenium configurations in the `rails_helper` file. A few `driven_by` declarations in `rails_helper` are pretty much all we need and it just works.

#### Configuration

Our Gemfile should include the following gems:

```ruby

#Gemfile

group :test do
	gem "capybara"
	gem "selenium-webdriver"
	gem "rspec-rails"
end
```

The `rails_helper` configuration is also much simpler.

```ruby

#spec/rails_helper.rb

RSpec.configure do |config|

	config.before(:each, type: :system) do
		driven_by :rack_test # rack_test by default, for performance
	end

	config.before(:each, type: :system, js: true) do
		driven_by :selenium_chrome_headless # selenium when we need javascript
	end
end
```

You might notice we're using `rack_test` as our default driver for performance; you can refer to [this article for more details](https://thoughtbot.com/blog/rack_test-or-selenium).

#### Git history Gotcha

When migrating to system specs you'll need to move your specs files from `spec/features/` to `spec/system/`. This will mess up the git history of those files as it will look like they were first created as part of that change. Old commits for the feature files will not be
automatically tied to that file.

However, if you have [`log.follow`](https://git-scm.com/docs/git-log#Documentation/git-log.txt---follow) set to `true` in your `gitconfig`, then
Git will track the history back through the old filename and the
complete history will be visible.

#### Additional resources

[Ruby on Rails 5.1 Release Notes](https://guides.rubyonrails.org/5_1_release_notes.html)

[Rspec system specs documentation](https://rspec.info/documentation/3.8/rspec-rails/#system-specs-feature-specs-request-specs-what-s-the-difference)

[Upgrading to RSpec 3.7.2 and system specs](https://everydayrails.com/2018/01/08/rspec-3.7-system-tests.html)

Have fun writing system specs 🎉
