do I have to manually clear out the database after a story runs? Seems like the data the story left is still in there. Joe
On Wed, 19 Mar 2008, Joe Van Dyk wrote:> do I have to manually clear out the database after a story runs?I''m wondering the same, but with specs. Database gets dirty and tests start to fail when i repeatedly do rake spec. -- Tero Tilus ## +358 (0)50 3635 235 ## http://www.tilus.net/koti/tero/
On 3/20/08, Tero Tilus <tero at tilus.net> wrote:> On Wed, 19 Mar 2008, Joe Van Dyk wrote: > > do I have to manually clear out the database after a story runs? > > > I''m wondering the same, but with specs. Database gets dirty and > tests start to fail when i repeatedly do rake spec.>From what I''ve seen, the test infrastructure (which RSpec takes fromthe Rails Test::Unit based code) relies on fixtures to initialize the database BEFORE running tests. The setup code clears any tables for which fixtures are declared, then loads those fixtures. It''s a little counterintuitive that the tables don''t get cleared AFTER the test, but I guess it makes sense in that without clearing before loading those tables wouldn''t be in a known state at the beginning of the test. What I''ve done is to have fixtures with a single record for tables I want to ''clear''. Alternatively you can do something like: MyModel.delete_all For any tables you want to clear, in the before block for tests, or in the xxx_story.rb for stories. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/
On Thu, Mar 20, 2008 at 4:02 AM, Rick DeNatale <rick.denatale at gmail.com> wrote:> On 3/20/08, Tero Tilus <tero at tilus.net> wrote: > > On Wed, 19 Mar 2008, Joe Van Dyk wrote: > > > do I have to manually clear out the database after a story runs? > > > > > > I''m wondering the same, but with specs. Database gets dirty and > > tests start to fail when i repeatedly do rake spec. > > >From what I''ve seen, the test infrastructure (which RSpec takes from > the Rails Test::Unit based code) relies on fixtures to initialize the > database BEFORE running tests. > > The setup code clears any tables for which fixtures are declared, then > loads those fixtures. > > It''s a little counterintuitive that the tables don''t get cleared AFTER > the test, but I guess it makes sense in that without clearing before > loading those tables wouldn''t be in a known state at the beginning of > the test. > > What I''ve done is to have fixtures with a single record for tables I > want to ''clear''. Alternatively you can do something like: > > MyModel.delete_all > > For any tables you want to clear, in the before block for tests, or in > the xxx_story.rb for stories.Seems like the tables should get cleared before and after the tests?