Search code examples
ruby-on-railsfactory-botfixturesfabrication-gem

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?


Solution

  • 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.