[RUBY] RSpec setup

This is the first post of qiita. I read everyday-rails and want to write a test using RSpec from now on, so I decided to write it as a memorandum. If you have any questions, I would appreciate it if you could point them out in the comments.

Add Gem

Add the following to bundle intall

Gemfile


group :development, :test do
  gem 'rspec-rails'
  # Factory_When using a bot
  gem 'factory_bot_rails'
end

group :development do
  gem 'spring-commands-rspec'
end

RSpec settings

$ rails g rspec:install

Execute the above command and add the following to the created .rspec. Adding this flag makes the spec output easier to read (there are other --warnings flags, etc.)

.rspec


--format documentation

Then execute the following command. bin/rspec is created.

$ bundle exec spring binstub rspec

Generator settings

Set Rails to have a spec file for RSpec created with you when you add code to your application using the rails generate command. Set false if you don't want it to be created automatically. (If you don't want to create controller specs, controller_specs: false)

config/application.rb


class Application < Rails::Application
  config.generators do |g|
    g.test_framework :rspec,
      view_specs: false,
      helper_specs: false,
      routing_specs: false
  end
end

Recommended Posts

RSpec setup
RSpec Setup
Introduction to RSpec 2. RSpec setup
Keycloak setup
Introducing RSpec
RSpec preparation
Install RSpec
RSpec Basics
Rspec, TDD (1)
Hello RSpec
Rspec introduction memo_Rails
JavaCC setup procedure
CentOS8 basic setup
Rspec Basics [Rails]
[Rails5] Rspec -validation-
About RSpec (Rails)