[RAILS] FactoryBot Register multiple data with the same model

How to generate multiple data of the same model in Rspec model test

How to generate

factories/tweets.rb


FactoryBot.define do
  factory :tweet_1,class: Tweet do
    text {"Good morning"}
  end

  factory :tweet_2,class: Tweet do
    text {"Hello"}
  end

  factory :tweet_3,class: Tweet do
    text {"Good evening"}
  end
end

How to define

spec/models/tweets_spec.rb


let(:tweet_a) { create(:tweet_1) }
let(:tweet_b) { create(:tweet_2) }
let(:tweet_c) { create(:tweet_3) }

Recommended Posts

FactoryBot Register multiple data with the same model
[Rails] Register by attribute of the same model using Devise
Run multiple applications with the same logic under Struts environment
How to use the same Mapper class in multiple data sources with Spring Boot + MyBatis
Setting to start multiple units at the same time with Vagrant
[Register multiple photos] Register multiple rails images at the same time Primitive power technique
[Rails] How to register multiple records in the intermediate table with many-to-many association
Start SQL Server with Docker & register initial data
Assignment to multiple variables with the ternary operator
[NCMB] I searched the data store with mbaas
Create related data together with FactoryBot for yourself
Understanding the MVC framework with server-side Java 2/4 Model
Form and process file and String data at the same time with Spring Boot + Java
How to change the action with multiple submit buttons
[Rails] Put together the same code with controller actions
Java desktop with the same front end as the WEB.