Attribute overrides

No matter which strategy is used, it's possible to override the defined attributes by passing a hash:

# Build a User instance and override the first_name property
user = build(:user, first_name: "Joe")
user.first_name
# => "Joe"

Ruby 3.1's support for omitting values from Hash literals dovetails with attribute overrides and provides an opportunity to limit the repetition of variable names:

first_name = "Joe"

# Build a User instance and override the first_name property
user = build(:user, first_name:)
user.first_name
# => "Joe"