From c701d9728853292d06f6192974f160e79ec09855 Mon Sep 17 00:00:00 2001 From: ahmadalguydi Date: Fri, 31 Jul 2026 12:01:21 +0300 Subject: [PATCH] docs: add factory usage quickstart --- README.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/README.md b/README.md index 66930b3f0..d44debe78 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,26 @@ To install the gem manually from your shell, run: gem install factory_bot ``` +## Quick Start + +Define a factory for a model in `spec/factories/users.rb`: + +```ruby +FactoryBot.define do + factory :user do + name { "Jane Doe" } + email { "jane@example.com" } + end +end +``` + +Use the factory in a test or other Ruby code: + +```ruby +user = FactoryBot.build(:user) # Build an in-memory user. +saved_user = FactoryBot.create(:user) # Persist a user through the model layer. +``` + ## Supported Ruby versions Supported Ruby versions are listed in `.github/workflows/build.yml` ([source](https://github.com/thoughtbot/factory_bot/blob/main/.github/workflows/build.yml))