Answer the question
In order to leave comments, you need to log in
Can you help me understand the syntax?
Hello.
I'm watching FactoryGirl right now.
I don't understand the construction
FactoryGirl.define do
factory :home do
#потом заполняются поля и сохраняются
end
end
test = create (:home)
factory :home do
...
end
Answer the question
In order to leave comments, you need to log in
factory is a method that is passed a :home parameter (in Ruby, as you know, parentheses can be omitted) and a block (everything between do and end). factory is called in a block, which is passed to FactoryGirl.define, where define is a method of the FactoryGirl class. And, yes, all this is the same DSL.
test = create (:home) - in fact, the full entry looks like FactoryGirl.create(:home). Just to avoid writing the FactoryGirl class all the time, its methods are included in the spec_helper.rb file: config.include FactoryGirl::Syntax::Methods
The topic is rather difficult to understand. How FactoryGirl works is very well written in the article https://robots.thoughtbot.com/writing-a-domain-spe... - your own FactoryGirl is written there with an explanation of all points.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question