When I launch the rail console in development, I see FactoryGirl objects creating objects. Itβs clear that I am doing it wrong, but how to do it right? This code makes my tests work ...
# tests/factories/board.rb FactoryGirl.define do factory :word do sequence(:text) { |n| "FAKETEXT#{n}" } end factory :board do trait :has_words do words [ FactoryGirl.create(:word, id: "514b81cae14cfa78f335e250"), FactoryGirl.create(:word, id: "514b81cae14cfa7917e443f0"), FactoryGirl.create(:word, id: "514b81cae14cfa79182407a2"), FactoryGirl.create(:word, id: "514b81cae14cfa78f581c534") ] end end end
Please note that my config directory does not mention factory anything in any file, so any download happens automatically with a gem. The relevant part of my Gemfile reads:
# Stuff not to use in production group :development, :test do # Command-line debugger for development gem "debugger" # for unit testing - replace fixtures gem "factory_girl_rails" end
So I could just take a factory girl from the development environment. But I think the fact that these records are created before using the factory is a sign that I wrote my factory incorrectly. But if you tell me that the factory is spelled correctly, I will just do it.
Leopd source share