Tuesday 15 April 2014

ruby on rails - Is it worth trying to reuse test fixtures as much as possible? -



ruby on rails - Is it worth trying to reuse test fixtures as much as possible? -

i have work rails fixtures on existing project. switching factorygirl or not option.

in fixtures have generic 1 time (records appear in production database) plus fair portion of fixtures testing border cases. in case of blog app latter blog no posts, blog haven't been active while, or blog no follower.

what take on creating separate set of fixture records every border case versus trying reuse existing fixtures much possible? latter include mocking / stubbing calls specific methods (e.g. account.any_instance.expects(:post_limit).returns(1000) mocha) or creating records inconsistent application logic (say, having several users per business relationship when app allows have 1 user per account).

i avoid creating info fixtures uncommon utilize cases. if have few scenarios checked in multiple parts of app create them in fixtures because consider part of test language of app.

for border cases create info in test. either modifying known fixture record, or creating new records meet border case criteria. don't need tools mill girl create reusable factories. (every activerecord model factory.) can create named methods in module , include in test class.

i not mock models outlined. create records in test , test application behaves correctly.

def test_lots_of_posts business relationship = new_account_with_n_posts 100 assert(account.posts > 5) end def new_account_with_n_posts count business relationship = account.create! name: "temp account" count.times |n| account.posts.create! title: "temp post #{n}" end business relationship end

ruby-on-rails testing minitest

No comments:

Post a Comment