Howto: Rails 6 + RSpec + Apparition
EDIT: Apparition is in the disrepair, the last commit is from 21. July 2021 and in my project Apparition just hangs and I can’t even close the console. I’d try something else, like headless Chrome with Selenium, unfortunately with stock Chromedriver. If you are using Docker, you can use selenium/standalone-chrome image which includes Chromedriver and just set capybara driver to remote (howto coming soon).
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
spec/rails_helper.rb with this:
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
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