Factory Girl - what's the purpose?

前端 未结 3 1264
陌清茗
陌清茗 2020-12-22 23:03

What\'s the purpose of Factory Girl in rspec tests when I could use before(:each) blocks? It feels like the only difference between Factory Girl and a bef

3条回答
  •  攒了一身酷
    2020-12-22 23:52

    FactoryGirl replaces fixtures in tests. This way, you won't have to keep the fixtures up-to-date as you change the data model. Fixtures can also tend to get unwieldy as you add more edge cases.

    FactoryGirl generates data on the fly and adding and removing fields is much easier. Also, you can use it in setup just how you'd use fixtures.

    Does that make it clearer?

提交回复
热议问题