[RUBY] [Rails] I want to test with RSpec. We support your step [Introduction procedure]

Reference target person

--For those who want to test with RSpec on Rails6.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 a configuration file with a generator.

.rspec


--require spec_helper
--format documentation

Set the test to document format.

Browser test to introduce System Spec

Gemfile


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

First, install the gem.

spec/rails_helper.rb


RSpec.configure do |config|
#Added 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 RSpec settings so that the browser test works.

Recommended Posts

[Rails] I want to test with RSpec. We support your step [Introduction procedure]
I want to test Action Cable with RSpec test
I want to play with Firestore from Rails
Introduction to RSpec 1. Test, RSpec
[Rails] Test with RSpec
I want to authenticate users to Rails with Devise + OmniAuth
Introduction to RSpec 4. Create test data with Factory Bot
I want to push an app made with Rails 6 to GitHub
I was addicted to setting default_url_options with Rails devise introduction
[Java] I want to test standard input & standard output with JUnit
Let's unit test with [rails] Rspec!
I want to convert an array to Active Record Relation with Rails
I want to add a browsing function with ruby on rails
[Rails] I want to add data to Params when transitioning with link_to
[Ruby on Rails] View test with RSpec
I want to use DBViewer with Eclipse 2018-12! !!
I want to write a unit test!
[Ruby on Rails] Controller test with RSpec
[Ruby on Rails] Model test with RSpec
I want to introduce the committee with Rails without getting too dirty
I want to be able to read a file using refile with administrate [rails6]
Rails6 I want to make an array of values with a check box
I want to use java8 forEach with index
Rails beginners tried to get started with RSpec
I want to perform aggregation processing with spring-batch
Rspec: I want to test the post-execution state when I set a method on subject
I want to hit the API with Rails on multiple docker-composes set up locally
[Rails] From test preparation to model unit testing [RSpec]
I want to use a little icon in Rails
I want to dark mode with the SWT app
I want to monitor a specific file with WatchService
I want to transition screens with kotlin and java!
I want to click a GoogleMap pin in RSpec
I want to get along with Map [Java beginner]
I want to redirect sound from Ubuntu with xrdp
Test Nokogiri with Rspec.
Rails, RSpec installation procedure
Introduction to RSpec 2. RSpec setup
I tried to make an introduction to PHP + MySQL with Docker
I want to randomly generate information when writing test code
[Rails] [bootstrap] I want to change the font size responsively
[Rails] I tried to create a mini app with FullCalendar
I want to make a list with kotlin and java!
I want to make a function with kotlin and java!
I want to create a form to select the [Rails] category
How to test a private method with RSpec for yourself
[Rails] I want to display "XX minutes ago" using created_at!
[Rails] I tried to implement batch processing with Rake task
Even in Java, I want to output true with a == 1 && a == 2 && a == 3
I want to manually send an authorization email with Devise
[Rails] Integration test using Capybara (from introduction to simple test execution)
I want to distinct the duplicated data with has_many through
I want to pass the startup command to postgres with docker-compose.