I will not hesitate anymore! RSpec introduction flow

What is RSpec

A Gem used when writing unit test code in Rails.

Rough flow until just before writing test code

  1. Added to Gemfile
  2. Install Gem
  3. Install rspec
  4. Make the test code visible on the terminal
  5. Add FactoryBot and Faker Gem to Gemfile
  6. Install Gem
  7. (Prepare a test image)

1. Added to Gemfile

Write gem'rspec-rails'. Be sure to be in the group: development,: test do ~ end </ font>

Gemfile


group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
  gem 'rspec-rails'
end

2. Install Gem

Make sure the current directory is the directory of the application that uses the test code in the terminal

bundle install

3. Install rspec

rails g rspec:install

This will generate a "spec directory" and a ".rspec file"

4. Make the test code visible on the terminal

.rspec


--format documentation

Is added.

5. Add FactoryBot and Faker Gem to Gemfile

Introduce Gem as needed. This time, we are assuming a chat application, so we introduced it.

Gemfile


group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
  gem 'rspec-rails'
  gem 'factory_bot_rails'
  gem 'faker'
end

Described in the same group as before. </ font>

6. Install Gem

bundle install

7. (Prepare a test image)

Placed in public / images with the file name "test_image.png ".

point

-[x] rspec can be used only by doing "rails g rspec: install" as well as "bundle install". -[x] Describe in the group of group: development,: test do ~ end.

Finally

bundle install just got into Rails! Image to unzip with rails g rspec: install!

Detailed test code on another occasion.

Recommended Posts