FactoryBot 도입 절차
처음에
FactoryBot 배포 절차를 메모에 남겨 둡니다.
이번에는 RSpec의 도입은 끝나고 있는 전제로 써 갑니다.
Gem 도입
Gemfile의 group :development, :test do~end 안에
gem 'factory_bot_rails'의 설명을 작성합니다.

작성한 후 bundle install 명령을 터미널에 입력하십시오.
bundle install
파일 만들기
spec 디렉토리 바로 아래에 factories 폴더를 만듭니다.
factories 폴더의 ruby 파일을 만듭니다. 다음 이미지처럼 보입니다.

파일 내용을 쓰기

이번에는 Faker를 사용하고 있습니다만 내용은 할애합니다. 기본 {} 안에 기술하면 괜찮습니다.
FactoryBot을 사용할 수 있도록 한다.

이미지처럼 FactoryBot.build(:user) 라고 써서 사용할 수 있습니다. 이미지는 인스턴스 변수에 할당하여 @user에서 사용할 수 있도록합니다.
이상이 됩니다. 초학자 때문에 실수 등 있으면 지적하실 수 있으면 다행입니다.
다음 번에는 모델의 이상계 단위 테스트 코드에 대해 써 갑니다.
Reference
이 문제에 관하여(FactoryBot 도입 절차), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/nakanowatari-taiki/items/c3d080aaa64e2ad7aea9텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)