egervari
2011-May-11 18:54 UTC
Running Ruby/Rails Specs with database inserts from non-default spec sub-directory
Hi everyone! I have a question on how to setup my tests a bit differently than the defaults. 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 solution?) 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 in ''specs/models''. 1. Do I need to manually clean out the data since I moved the specs into it''s own spec/squeries subdirectory? 2. Is there any way to include spec/queries to the list of directories that get auto-cleaned, much like spec/models does? Thanks -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
David Kahn
2011-May-11 19:00 UTC
Re: Running Ruby/Rails Specs with database inserts from non-default spec sub-directory
On Wed, May 11, 2011 at 1:54 PM, egervari <ken.egervari-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi everyone! > > I have a question on how to setup my tests a bit differently than the > defaults. > > 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 > solution?) > > 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 > in ''specs/models''. > > 1. Do I need to manually clean out the data since I moved the specs > into it''s own spec/squeries subdirectory? > > 2. Is there any way to include spec/queries to the list of directories > that get auto-cleaned, much like spec/models does? >There is a gem called database_cleaner which might help in your case to run before your test/suite.> > Thanks > > -- > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
egervari
2011-May-11 19:05 UTC
Re: Running Ruby/Rails Specs with database inserts from non-default spec sub-directory
> There is a gem called database_cleaner which might help in your case to run > before your test/suite.Well, I''m looking into that now... and it mostly works (But not quite... it seems like there are some records hanging around still). Why do I not need the database cleaner for the model tests... but I do for this new spec/queries directory? Can I simply tell rails to treat this directory the same as it treats spec/models? The tests work in that folder. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.