Howto: Rails 6 + RSpec + Apparition

In this howto we'll setup system tests of Ruby on Rails 6 application to work with Apparition driver for Capybara. Apparition uses Chromedriver driver to drive Chrome or Chromium directly - headless mode is default, but can be set up to show the browser.

I sort of assume RSpec is already set up.

Now we add apparition into test group in Gemfile.

group :test do
  # ...
  gem 'apparition'
end

And run bundle install.

Update spec/rails_helper.rb with this:

# require 'rspec/rails'

# these two lines are for us who use development builds of Chromium
# from brew
require 'webdrivers'
Webdrivers::Chromedriver.required_version = '79.0.3945.36'

require 'capybara/apparition'
Capybara.javascript_driver = :apparition

# Add additional requires below this line. Rails is not loaded until this point!
# ...

And now tell a system test to use apparition:

require "rails_helper"

RSpec.describe "See all articles grouped by category", type: :system do
  before do
    driven_by(:apparition)
  end

  it "enables me to create widgets" do
    visit "/browse"
    expect(page).to have_text(":: myrtana/Site News")
    expect(page).to have_text("!!! Get my myrtana off the ground !!!")
  end
end

And it works!

$ bin/rspec spec/system/browse_content.spec.rb
DEPRECATION WARNING: action_view.finalize_compiled_template_methods is deprecated and has no effect (called from <top (required)> at /Users/afterparty/softworks/oni_sorceress/config/environment.rb:5)
Capybara starting Puma...
* Version 4.3.0 , codename: Mysterious Traveller
* Min threads: 0, max threads: 4
* Listening on tcp://127.0.0.1:53741
.

Finished in 4.15 seconds (files took 2.23 seconds to load)
1 example, 0 failures

The only thing I don't know is why I have to set Capybara.javascript_driver = :apparition, but also driven_by in a test itself. Otherwise a browser is shown. Which probably means it used Selenium driver which I haven't yet removed from Gemfile.