In the past I've relied upon transactional fixtures, as a compromise, to overcome this problem. As above, I typically prefer making sure there is no data in the db before a test run, but when I've had to handle a lot of data transactional fixtures have sped things up greatly.
On Mar 16, 11:54 am, Xavier Shay <[email protected]> wrote: > In which I wave my hands a lot. I haven't thought this through totally, > but thought I'd throw it out there. > > Problem: > - My specs are slow oh no! > - Setting up objects/object trees takes heaps of time > - There's a *lot* of duplication in object creation in most test suites > > Solution: > - Add 'smarts' to machinist* so that it auto-generates fixtures for > common objects and keeps them in the DB > > Downside: > - You can't rely on your DB being 'clean' > ... but if you're using should change_by and friends that often > won't be an issue > - It doesn't actually exist and may even be impossible > > Idea: > - Either some sort of profiling, where machinist records object creation > and builds up a library (so first run will be just like normal, second > run will be optimized) > > it 'a' do > user = User.make > end > > it 'b' do > user = User.make > end > > it 'c' do > user = [User.make, User.make] > end > > This spec should only require 2 creations, not 4. This example would be > trivial to implement - keep track of how many users are created in each > example, then before all the transactional stuff for the next suite run, > create a few users that can be used (fixtures) rather than creating new > ones. You can have smarts so that if a particular object is only needed > once or twice, then just create it on the fly rather than > pre-generating. For more complex cases may need some 'hints' or what > what for it to work. Have to come up with more examples. > > I (and I know a few others) use a before(:all_transactional) hook to > fake this behavior in some of our specs - if object creation takes 1s > and you want to spec 15 attributes, that's a 15x speed up. > > I imagine this would subtley change how you write specs, so may not be > able to be retrofitted on to big projects - but I reckon this could be a > big win for large functional suites. > > Discuss! Already done it? Handy idea? What examples break it? > > Xav > > * where ever I say machinist just insert "some sort of object factory thing" -- You received this message because you are subscribed to the Google Groups "Ruby or Rails Oceania" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rails-oceania?hl=en.
