12
votes

After watching a RailsConf video on ActionDispatch::systemTestCase, I was excited to incorporate it into my current app. Currently our test suite setup uses the following:

It was difficult to get the configuration working for our current setup, but we eventually got it working, thanks largely to an article by Avdi Grimm titled: Configuring database_cleaner with Rails, RSpec, Capybara, and Selenium.

My hope was to use the built-in system tests of rails released in rails 5.1. Since rails now has system testing built in: all I would need to worry about configuring is the following:

  • rspec
  • factory_girl

And that is it because ActionDispatch::systemTestCase takes care of capybara, database_cleaner, and it is already configured for the selenium driver.

For example: currently my feature specs are written like so (Capybara within the context of RSpec):

#spec/features/blogs/creating_blogs_spec.rb
require "rails_helper"

RSpec.feature "Logged in User can create a blog" do
  before do
    create(:logged_in_user)
  end

  scenario "successfully", js: true do
    ...
  end
end 

So this is what a typical integration/feature/system spec might look like for a test suite configured with rspec, database_cleaner, factory_girl, and capybara. I would like to convert it over to using ActionDispatch::systemTestCase.

However: I would like to use ActionDispatch::systemTestCase within the context of RSpec.

The RailsConf video above shows how ActionDispatch::systemTestCase works within the context of rails' default test suite layout (ex: minitest with tests located in a test directory), but it did not discuss how to use ActionDispatch::systemTestCase within the context of RSpec.

I could not find any resources on making rails' built-in system tests configurable with RSpec, including within the system testing section of the rails guides. Is this possible?

2

2 Answers

15
votes

Update October 2017:

Rspec-rails 3.7 is now fully compatible with system tests.

Basically, this is all you have to add to your spec_helper.rb:

RSpec.configure do |config|
  config.before(:each, type: :system) do
    driven_by :rack_test
  end

  config.before(:each, type: :system, js: true) do
    driven_by :selenium_chrome_headless
  end
end

https://medium.com/table-xi/a-quick-guide-to-rails-system-tests-in-rspec-b6e9e8a8b5f6

4
votes

According to the RailsConf Talk: Teaching RSpec to Play nice with Rails, as of rspec-rails 3.6.0 it is not compatible with rails' system test integration.

It does appear that compatibility is being worked on via this pull request.