I thought it would be difficult to get used to it unless I summarized how to create RSpec unit test code so that I could understand it at a glance, so I tried to summarize the creation procedure myself.
group :development, :test do
#abridgement
gem 'rspec-rails'
end
·Terminal % bundle install
--require spec_helper
--format documentation
group :development, :test do
#abridgement
gem 'rspec-rails'
gem 'factory_bot_rails'
gem 'faker'
end
·Terminal % bundle install
(Example) spec/factories/users.rb
FactoryBot.define do
factory :user do
nickname {Faker::Name.last_name}
email {Faker::Internet.free_email}
password {Faker::Internet.password(min_length: 6)}
#When using 6 characters or less ↑
password_confirmation {password}
end
end
(Example) spec/models/user_spec.rb
require 'rails_helper'
RSpec.describe User, type: :model do
before do
@user = FactoryBot.build(:user)
end
end
(Example) spec/models/user_spec.rb
describe 'New user registration' do
it "nickname and email, password and password_You can register if confirmation exists" do
end
・ ・ ・
end
I hope I can make it to some extent by looking at this without memorizing it.
Recommended Posts