ruby 2.5.7 Rails 188.8.131.52 OS: macOS Catalina
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.
--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.
Make changes in group: test do in the Gemfile. Delete the default description and write the following 4 gems instead.
group :test do gem 'capybara', '>= 2.15' gem 'rspec-rails' gem "factory_bot_rails" gem 'faker' end
$ 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.active_support.deprecation = :stderr ↓ config.active_support.deprecation = :silence
Then do the following:
$ 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.