[Ruby on Rails] Until the introduction of RSpec

Development environment

ruby 2.5.7 Rails 5.2.4.3 OS: macOS Catalina

What is RSpec?

It is a test tool often used in Rails, and if you write a test code, it will automatically test the operation of the application. You can also install it with gem.

RSpec configuration

--describe: Test title --context: Used to divide the title into details --before: Use if there is a necessary description before executing the contents of it --it: Test content

Of these, describe and it are indispensable.

Install RSpec

Make changes in group: test do in the Gemfile. Delete the default description and write the following 4 gems instead.

Gemfile


group :test do
  gem 'capybara', '>= 2.15'
  gem 'rspec-rails'
  gem "factory_bot_rails"
  gem 'faker'
end

Terminal


$ bundle install
$ rails g rspec:install

After execution, a spec folder will be created under app, so We will edit this and run the test.

Also, change the following at the bottom of config / environments / test.rb to: silence.

config/environments/test.rb


config.active_support.deprecation = :stderr
↓
config.active_support.deprecation = :silence

Then do the following:

Terminal


$ rails db:migrate RAILS_ENV=test

Installation is OK up to this point.

From next time controller、model、view I will show you how to test.

Recommended Posts

[Ruby on Rails] Until the introduction of RSpec
[Ruby on Rails] Introduction of initial data
part of the syntax of ruby ​​on rails
Docker the development environment of Ruby on Rails project
Try using the query attribute of Ruby on Rails
Basic knowledge of Ruby on Rails
[Ruby on Rails] Stop "looping until ..."
(Ruby on Rails6) Display of the database that got the id of the database
Delete all the contents of the list page [Ruby on Rails]
A note about the seed function of Ruby on Rails
[Rails] Addition of Ruby On Rails comment function
[Ruby on Rails] View test with RSpec
Let's summarize "MVC" of Ruby on Rails
[Ruby on Rails] Controller test with RSpec
[Ruby on Rails] Japanese notation of errors
[Ruby on Rails] Model test with RSpec
Explanation of Ruby on rails for beginners ①
[Ruby on rails] Implementation of like function
Understand code coverage with Rspec, the Ruby on Rails test framework
[Ruby on Rails] Change the save destination of gem refile * Note
I summarized the flow until implementing simple_calendar in Ruby on Rails.
Implementation of Ruby on Rails login function (Session)
Introducing Rspec with Ruby on Rails x Docker
[Rails] Introduction of PAY.JP
When the Ruby on Rails terminal rolls back
Recommendation of Service class in Ruby on Rails
Publish the app made with ruby on rails
[Ruby on Rails] Select2 introduction memo for Webpacker
Rails new in Ruby on Rails ~ Memorandum until deployment 2
Ruby on Rails ~ Basics of MVC and Router ~
Introducing Rspec, a Ruby on Rails test framework
Ruby on Rails Elementary
[Ruby on Rails] A memorandum of layout templates
Ruby on Rails basics
Rails new in Ruby on Rails ~ Memorandum until deployment 1
How to solve the local environment construction of Ruby on Rails (MAC)!
Ruby On Rails Association
Determine the current page with Ruby on Rails
Ruby on Rails When you don't know the cause of rollback when saving.
[Ruby On Rails] How to search the contents of params using include?
[Ruby on Rails] Individual display of error messages
[Ruby on Rails] How to make the link destination part of the specified id
[Ruby on Rails] Rails tutorial Chapter 14 Summary of how to implement the status feed
[Ruby on Rails] Implement a pie chart that specifies the percentage of colors
[Ruby on Rails] How to Japaneseize the error message of Form object (ActiveModel)
[Ruby on Rails] Asynchronous communication of posting function, ajax
[Introduction] Try to create a Ruby on Rails application
Implementation of Ruby on Rails login function (devise edition)
Run Ruby on Rails RSpec tests with GitHub Actions
[Ruby on Rails] How to change the column name
[Ruby on Rails] Implementation of tagging function/tag filtering function
Solve the N + 1 problem with Ruby on Rails: acts-as-taggable-on
Explanation of Ruby on rails for beginners ⑥ ~ Creation of validation ~
Explanation of Ruby on rails for beginners ② ~ Creating links ~
(Ruby on Rails6) Reflecting the posted content from the form
Explanation of Ruby on rails for beginners ⑦ ~ Flash implementation ~
Ruby on rails learning record -2020.10.03
[Rails] Introduction of devise Basics
Portfolio creation Ruby on Rails
Ruby on rails learning record -2020.10.04
[Ruby on Rails] Debug (binding.pry)