ruby on rails - Is it a bad idea to write invalid FactoryGirl factories/traits? -
listening giant robots smashing other giant robots podcast, heard want factorygirl factories minimal, providing attributes make object valid in database. being said, talk went on traits way define specific behavior based on attribute may change in future.
i'm wondering if it's idea have traits defined purposefully fail validations clean spec code. here's example:
factory :winner user_extension "7036" contest_rank 1 contest trait :paid paid true end trait :unpaid paid false end trait :missing_user_extension user_extension nil end trait :empty_user_extension user_extension "" end end will allow me call build_stubbed(:winner, :missing_user_extension) in specs in tests intend fail validations. suppose further explicit fail nesting these bad factories under factory called :invalid_winner, i'm not sure if that's necessary. i'm interested in hearing others' opinions on concept.
no it's not idea, wont make specs clear understand after while, , later when code evolve factory fail today may not fail anymore, , have hard time review specs.
it way better write test 1 identified thing. if want check saving fails mandatory parameter missing, write regular factory , add parameters overwrite values factory:
it 'should fail' create :winner, user_extension: nil ... end
Comments
Post a Comment