Robert, That's just a side effect from using a factory instead of fixtures, especially if you're building up large object graphs.
Some things I've noticed from working on big projects, think upwards of 10,000 tests: Use before(:all) where possible, you've already mentioned this. If you can keep the object graph in memory, your test will run faster. I know you can do this with machinist, not sure about factory girl. Mocks and stubs are really useful for isolating parts of the object graph you're not trying to test but require to be present. Maybe look into that? If you've just been merrily adding tests while developing your application you may have built yourself a monster where you're testing the exact same code in 3 or 4 places. It's pretty easy to do this if you're not actively paying attention. You might want to spend a day or so going through your test suite trying to find duplication. One thing we've started doing in our new projects is monkey patching ActiveRecord to raise if an SQL statement includes 'INSERT'. The intention is that when we run our specs, we won't ever write to the database. These tests will then be super fast and able to run in parallel. Our cucumber tests will utilise the whole stack to ensure everything is working nicely. That way we should be able to find out quickly if an individual piece of our application is broken by running our specs, and find out if our app is completely hosed by running our cucumber tests. If all of that passes, then there's more tests down the line including some humans using the system. On 15/12/2010, at 11:58 AM, Robert Gravina wrote: > On 15 December 2010 07:52, dnagir <[email protected]> wrote: >> Hi Guys, >> >> I am a bit tired of waiting for for the [rails 3] specs to run after I >> save a file. After saving, I have to wait 10 secs or so for my specs >> only to be executed (by autotest). >> > > 10 seconds! That sounds positively snappy compared to what I have to > endure. I have some individual specs in one (Rails 2.3.9) app that > take longer than that (!), and whole suite takes 2 - 3 hours on my > machine.... which makes using autotest impossible :(. We have a > buildbot server which runs them in parallel on a beefy machine so I > (only) have to wait 15 - 20 minutes for a response from the CI server, > but it's still long enough to be a hindrance to testing. > > I've been trying to fix this by moving setup from before do ..end into > a before :all block [1] but some issues (db not being cleared between > specs and factories trying to re-inset records that already exist) > persist. Some tests create 10 - 15 models, are parse some big json > file before running *each* example, so I have a fair idea why they are > running so slowly. I haven't been able to find anything similar to > loading fixtures before the whole test suite with factory girl, but I > suspect it's just because I don't have all that much experience with > it. > > Has anyone seen some examples of rspec + factory girl + setup before > all tests in the wild? I've found Pretty much every rspec + factory > girl example I can find uses the standard before do ... end block for > setup as it's probably fine for most test suites.... maybe I need to > just search the githubs? > > Apologies for hijacking this thread, by the way! > > Thanks all for your advice, > > Robert > > [1] http://blog.andrewbruce.net/optimizing-specs-for-activerecord-scopes > > -- > 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. > -- 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.
