Gems, such as Factory Girl and Sham , allow you to create patterns for valid and repeated - useful objects. They were created in response to instruments in which fixed records were to be loaded into a database. They allow you to customize more when you create objects, and they aim to have a valid object to work with. They can be used anywhere in your tests and in your before and after test hooks.
before (: each), before (: all), after (: each) and after (: all) are all aimed at giving you room for customization and breaks to be used among the test group. For example, if you are going to create a new real user for each individual test, then you will want to do this in your hook (: each). If you are going to clear some files from the file system, you want to do this at the beginning. If your tests create a tmp file and you want to delete it after the test, you will do it in your own after (: each) or after (: all).
The differences between the two concepts are that factories are not aimed at creating hooks around your tests, they are aimed at creating real objects and Ruby records, so you can keep your object's flexibility dry. Before and after the interception, they are aimed at tuning and disassembling tasks, which are shared in a group of examples so that you can save the installation and break code DRY.
Pan Thomakos Mar 03 '11 at 17:22 2011-03-03 17:22
source share