I have a question on how to setup my tests a bit differently than the
By default, Rails with RSpec installed provides you with directories
such as spec/models, spec/controllers, etc.
When i use before(:each), I notice that Rails properly cleans out the
database in these specs automatically.
However, I created a new sub-directory called spec/queries. My
intention was to put all of my query-related tests here so that the
database setup code didn’t run with the model validation and business
logic tests (for speed and organization reasons). I will have a lot of
complex queries that will need to be tested against a mini-database…
so this seems like the right thing to do (or is there a better
When I put these tests in spec/queries folder and run the tests
multiple times, Rails complains that data is not unique and so on…
so I am guessing that the data is not getting cleaned out now? Yes, I
am using factory girl with sequences, so this is probably a database
cleaning problem. I didn’t have it before when these same tests were
Do I need to manually clean out the data since I moved the specs
into it’s own spec/squeries subdirectory?
Is there any way to include spec/queries to the list of directories
that get auto-cleaned, much like spec/models does?