FactoryFixtures is a Rails engine that provides an easier integration with Factory Girl.
Because Factory Girl it's not a direct reaplacement for yaml fixtures, this gem allows us to use factory_girl features when writing fixtures.
It currently offers one feature:
- Load fixtures written with factory girl syntax
- has_and_belongs_to_many associations
- Fixtures load when executing tests
And it's planned to support this features:
- Polymorphic associations
Supported ORMs:
- ActiveRecord
Invoke the task factory_fixtures:load $ rake factory_fixtures:load
This task will load the defined fixtures into the database
Given an Account model create a file named test/factory_fixtures/accounts.rb
define :verified_account do |a| a.is_verified true a.address { |a| "#{rand 100} - #{a.company}" } a.zip { "#{rand 10}" * 5 } end
create :test_poc, :verified_account do company 'test_poc' end
If the factory is not specified it will use a default factory with empty default values.
create :super_account, :verified_account do company 'super' distributor F(:distributor_mega) end
Invoke F method to fed up associations. :distributor_mega it's the name of a fixture, so distributor F(:distributor_mega) will set the column distributor_id to the identifier of the object :distributor_mega.
The unit tests classes must inherit FactoryFixtures::Unit::TestCase
class UserTest < FactoryFixtures::Unit::TestCase end
In the test methods users returns a hash with the fixtures' names as keys and the fixtures as values
factory_fixtures :accounts, :users, :devices
factory_fixtures loads the specified fixtures files and creates method whose names are the fixtures' names.
Copyright (c) 2010 "snmgian" / "mooveit", released under LGPL v3 license.
Contact at: snmgian at gmail dot com, gian.zas at moove-it dot com