On May 25, 9:23 pm, egervari <[email protected]> wrote: > It turns out, if I make the before(:each) block say this: > > before(:each) do > @user = User.new > controller.stub(:authenticate_user!) > controller.stub(:current_user).and_return(@user) > controller.stub(:add_secure_model_data) > > @site_update = SiteUpdate.new > @comment = Comment.new > end > > All 3 tests now run in 0.07 seconds! That is a 2000% improvement. >
not hitting the database helps! In the apps I work on now I've written a little test helper that allows you do do stuff like common_context do @user = Factory.create :user @product = Factory.create :product end unlike before(:each) this will only run once for a given context, but the @user and @product instance variables will get resurrected at the start of each examples. Database savepoints are used so that if an example modifies anything in the database it is rolled back before the next example runs. Nested contexts can each have their own common_context block. This only works for active record objects and can't deal with unsaved objects but that covers most of my needs (and of course you can still have a regular before(:each) for your other setup stuff) I've been meaning to write this up as a blog post for a while but haven't got round to this. Fred > I guess the solution is not to use factories at all for controller > tests. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" 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/rubyonrails-talk?hl=en.

