My test suite is plagued with intermittent test failures that I have been 
trying to fix for several months now with no success. As far as I can tell, 
it’s all race condition stuff that has to do with Database cleaner. I use 
exclusively Factories (FactoryGirl) 

Basically I have set up data using Factories in before(:each) calls at the 
top of all my tests.


before(:each) do
    FactoryGirl.create(:gallery_bucket)
    FactoryGirl.create(:promo_bucket)
end


When the spec runs, a line of code that is relatively global to my layout 
calls the following:

 def load_gallery
    @galleries = Spree::Bucket.find_by_slug('gallery').bucket_contents
  end

When this line of code runs,  Spree::Bucket.find_by_slug('gallery’) returns 
nil.

In some cases I have been able to debug both the before(:each) and have see 
the records returned correctly by Spree::Bucket.all (returns 2 records), 
but then when I continue and fall into a debugger inside of the 
load_gallery method, Spree::Bucket.all returns nil.

Like I said, it is intermittent, so Spree::Bucket.all returns 2 objects and 
everything passes. Other times, the objects just appear not to be available 
to the ruby instance. 

When I run the whole suite (about 80 tests) I get about  a 1 in 4 chance of 
at least 1 failure. When I run tests individually, they usually (although 
not always) pass.



Although I have tried different transaction/truncation strategies, the one 
I currently have can be seen here:
https://gist.github.com/jasonfb/953fca4c4788a70bb661

Interesting to note, when I switch to an all-transaction strategy, most of 
my test suite fails, particularly the Webkit (:js => true) tests. Using a 
transaction strategy for the non-Webkit tests and a truncation strategy for 
the Webkit tests seems to produce the best (least like to fail) results, 
but even that still has these intermittent failures. 


Any tips for where I should look next would be greatly appreciated.

-Jason



-- 
You received this message because you are subscribed to the Google Groups 
"rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rspec/9f3382d8-2e7b-45e9-ae46-8920f0c2c1e3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to