factory_bot: clarify ways to build
This commit is contained in:
parent
5f1d4265eb
commit
9c1c638048
|
@ -54,24 +54,30 @@ end
|
||||||
|
|
||||||
### Using
|
### Using
|
||||||
|
|
||||||
|
#### Build a model
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
FactoryBot.build(:user)
|
FactoryBot.build(:user)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Other ways
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
build(:user) # not saved
|
build(:user) # → model (not saved)
|
||||||
create(:user) # saved
|
create(:user) # → model (saved)
|
||||||
attributes_for(:user) # hash
|
attributes_for(:user) # → hash
|
||||||
build_stubbed(:user) # stubbed out attributes
|
build_stubbed(:user) # stubbed out attributes
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### With options
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
# With options:
|
|
||||||
build(:user, name: 'John')
|
build(:user, name: 'John')
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Lists
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
# List:
|
|
||||||
create_list(:user, 3)
|
create_list(:user, 3)
|
||||||
build_list(:user, 3)
|
build_list(:user, 3)
|
||||||
```
|
```
|
||||||
|
|
Loading…
Reference in New Issue