简体   繁体   中英

Factory_girl returning objects and fabricator returning an empty array why?

our test code is currently using factory_girl and I am trying to use fabrication for my tests to generate objects.

In Factory_Girl

batch = FactoryGirl.create(:transaction_batch)
puts batch  # print out a transaction object

In Factory Girls

batch = Fabricator(:transaction_batch)
puts batch # prints out an empty array

Could anyone tell me why the Fabricator is returning an empty array?

The FactoryGirl defines it's factories in spec/factories/transaction.rb , and there you have something like this:

FactoryGirl.define do
  factory :transaction_batch do
    first_name "John"
    last_name  "Doe"
  end
end

The Fabricator uses "fabrications" from a different location, like spec/fabricators/transaction_fabricator.rb

And there you don't have defined fabrication. That is the reason, or you have a blank fabrication like:

Fabricator(:transaction_batch) do
end

Create a fabrication for Fabricator, and you should be fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM