Adnan Ali
Adnan Ali

Reputation: 2960

create method in Rspec

I need to understand this line of code in Rspec.

create(:practice, creator: create(:physician, password: "password123", password_confirmation: "password123" ), phone: "+1 (555) 555-5554", office: "+1 (555) 555-5555", clinic_key: "abc123")

What is this create function. It is not built in rails or ruby function. Do we have its documentation?

Upvotes: 22

Views: 15499

Answers (1)

gotva
gotva

Reputation: 5998

It looks like create is called from FactoryBot.

Usually you need to create object like FactoryBot.create(:user) but if you configure factory bot

RSpec.configure do |config|
  config.include FactoryBot::Syntax::Methods
end

(see this) you can omit FactoryBot and use short variant create(:user).

So your code creates factory practice with creator which is created by another factory physician.

Upvotes: 28

Related Questions