When I boot up my rails console in development I see FactoryGirl creating objects. Clearly I'm doing it wrong, but what's the right way to do this? 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
Note there's no mention of factory anything in any file in my config
directory, so whatever loading is happening automatically by the 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 factory girl out of the development environment. But I think the fact that these records are being created before the factory is being used is a sign that I've written my factory incorrectly. But if you tell me the factory is written correctly, I'll just do that.
FactoryGirl
and see if it's called anywhere? – Piet