Setting this up took quite a bit of time and research for me, so just thought of sharing the learnings along the way that led to a working setup. - Initial error that I was getting with running System tests in Rails 6 ```ruby System test integration requires Rails >= 5.1 and has a hard dependency on a webserver and `capybara`, please add capybara to your Gemfile and configure a webserver (e.g. `Capybara.server = :webrick`) before attempting to use system tests. ``` - since the error above says specify `Capybara` in the Gemfile, a part of my Gemfile looked like below: ```ruby group :development, :test do gem 'capybara', '~> 3.13' gem 'factory_bot_rails' gem 'pry-byebug' gem 'rspec-rails' gem 'shoulda-matchers' gem 'webdrivers' end ``` - **What didn't work for me:** - From an [official wiki guide](https://github.com/heartcombo/devise/wiki/How-To:-sign-in-and-out-a-user-in-Request-type-specs-(specs-tagged-with-type:-:request)) of testing sign in of a user with Devise for request type specs: - Context: Although the title says it's the guide for request type specs but since content of the wiki also said `This is the equivalent of declaring include Devise::Test::IntegrationHelpers in an system/feature spec or Rails system/controller test.` , I was trying this out with system specs & it didn't work for me - Why this guide didn't work fully for me? - It specifies the usage of tests of type `request` with this line of code: `config.include Devise::Test::IntegrationHelpers, type: :request` but that throws an error for me which says undefined method `sign_in`(please read below for more context on what the `sign_in` method is for) when running the required system spec. My exact setup: Rails 6.0.3.rc1, Ruby: 2.6.0, RSpec 3.9, Capybara 3.32.1 - **Solution**: Steps that properly setup System tests for me in Rails 6 using RSpec & Devise : - For the `sign_in` (if you are using user sign in using Devise) method you need to implement the below steps to get up and running with system tests in Rails 6 - other general code required to make things for system tests with Rails 6 - **Step 1**: Specify `gem 'webdrivers'` in your Gemfile(already included as shown above) Why? - It's required for System tests to work with Rails 6 - More details [here](https://everydayrails.com/2019/04/09/chromedriver-helper-webdrivers.html) - **Step 2**: Specify the required driver for Capybara. Why? - This is required for System tests to work with Rails 6 - required code to be placed in the `RSpec.configure do |config|` block of your `rails_helper.rb` file: ```ruby config.before(:each, type: :system) do driven_by :selenium_chrome_headless end ``` - Please note: this is just one of the drivers that can be used here, there's a possibility that this would also work with other Capybara drivers also - **Step 3**: Specify the below helpers in the `RSpec.configure do |config|` block of your `rails_helper.rb` to make sure that the `sign_in` method is used to login the user into your app before testing the specific feature of your app which requires a signed in user ```ruby config.include Devise::Test::IntegrationHelpers, type: :system config.include Warden::Test::Helpers ``` - Reference credits: - [https://everydayrails.com/2019/04/09/chromedriver-helper-webdrivers.html](https://everydayrails.com/2019/04/09/chromedriver-helper-webdrivers.html) - [https://stackoverflow.com/questions/44269257/rails-5-1-configuring-built-in-system-tests-with-rspec](https://stackoverflow.com/questions/44269257/rails-5-1-configuring-built-in-system-tests-with-rspec) - [https://medium.com/table-xi/a-quick-guide-to-rails-system-tests-in-rspec-b6e9e8a8b5f6](https://medium.com/table-xi/a-quick-guide-to-rails-system-tests-in-rspec-b6e9e8a8b5f6) - [https://medium.com/@maguri/rails-5-system-tests-with-rspec-config-244fb9051606](https://medium.com/@maguri/rails-5-system-tests-with-rspec-config-244fb9051606) - [https://github.com/heartcombo/devise/wiki/How-To:-Test-with-Capybara](https://github.com/heartcombo/devise/wiki/How-To:-Test-with-Capybara) - [https://medium.com/@yutafujii_59175/a-simple-login-test-with-rspec-devise-factorybot-in-rails-29aeb2ebc4ab](https://medium.com/@yutafujii_59175/a-simple-login-test-with-rspec-devise-factorybot-in-rails-29aeb2ebc4ab)