Fixtures bad:
Get highly unmanageable, especially when someone decides to import real data (:user_275, :user_276...)
Live outside test.
Can't change loaded values easily.
Factories good:
Let you use sensible labels and tweak the created data.
They reduce dependence on external data (manipulate values right in the test).
FactoryGirl:
http://github.com/thoughtbot/factory_girl/tree/master
spec/factories/first_model.rb second_model.rb...
Code:
Factory.define :user {|f| f.name 'Joe'; f.zip '34279'; f.association :employer}
Factory(:user).should be_valid
Factory(:user, :name => nil).should_not be_valid
.association calls another factory (that you define) to generate associated model object.
Object Daddy:
http://github.com/flogic/object_daddy/tree/master
spec/exemplars/*_exemplar.rb
Code:
class User
generator_for :name => 'Test User'
generator_for :ssn, :start => '12343214' do {|prev| prev.succ}
end
@user = User.generate!
@user.should be_valid
[Barnes likes ObjectDaddy. I don't 'cause of modificat
Others:
machinist
foundry
fixjour