[Ruby] [Rails] I want to test with RSpec. We support such a step of you [Introduction procedure]

less than 1 minute read

Reference target person

  • For those who want to test with RSpec with Rails 6.0

environment

$ rails -v
Rails 6.0.3.1
$ ruby -v
ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-darwin19]

Introduce #RSpec

Gemfile


group :development, :test do
  gem'rspec-rails'
end
$ bundle install

$ rails g rspec:install

Install gem and create configuration file with generator.

.rspec


- -require spec_helper
- -format documentation

Set the test to document format.

Introducing #System Spec Browser test

Gemfile


group :test do
  gem'capybara','>= 2.15'
  gem'webdrivers'
end
$ bundle install

First, install gem.

spec/rails_helper.rb


RSpec.configure do |config|
# Add just before the bottom
  config.before(:each) do |example|
    if example.metadata[:type] == :system
      driven_by :selenium, using: :headless_chrome, screen_size: [1400, 1400]
    end
  end
end

Change the RSpec settings so that the browser test works.