Uros Certic
Uros Certic

Reputation: 31

Rails Factory Bot accessing passed values inside factory definition

Is there a way to access values that are passed into the create method inside a factory definition?

For example

create(:user, name: "Jon")

Is there a way to check in the after(:create) hook if a name was passed or if it is default one?

Upvotes: 0

Views: 394

Answers (1)

Brad Werth
Brad Werth

Reputation: 17647

You can just compare the attributes, like:

user.name == FactoryBot.attributes_for(:user)[:name]

Upvotes: 2

Related Questions