The problem is that the lights are terrible. Some time ago I read an article called The Lie , and it opened my eyes. This article focuses on the Machinist , which I used and loved, but currently prefer factory_girl . Here is a basic example from their README:
You define a Factory with a sufficient default value to pass the tests:
Factory.define :user do |u|
u.first_name 'John'
u.last_name 'Doe'
u.admin false
end
And then in your tests you can override or add values as needed (a contrived RSpec example)
describe User, "#is_admin?" do
before(:each) do
@user = Factory(:user, :admin => true, :email => 'jdoe@email.com')
end
it "should be true"
@user.is_admin?.should be_true
end
end
@user , , ActiveRecord, () . . , . , (save false, , ).
, , .