From: Vassilis Rizopoulos Date: 2007-06-29T05:49:52+09:00 Subject: Re: Getting fixtures to work without Rails Gregory Brown wrote: > > These posts might be helpful: > http://blog.floehopper.org/articles/2006/06/27/rails-fixtures-help-or-hindrance > > http://blog.floehopper.org/articles/2006/08/10/fed-up-with-rails-fixtures-part-one > > http://blog.floehopper.org/articles/2006/08/14/fed-up-with-rails-fixtures-part-two > > > In the context of Rails, I just do regular Model.create statements and > let the database cleanup after itself. In stuff outside of rails, I > some kind of hacky stuff that I can't really recommend. (Usually > manually blowing up DBs or calling destroy_all in cleanup) > > I'd be interested in a safe way to do this too, although if you use > mocks, you may not need it at all. > > Also, many of your tests won't require the data to be in the database. > Sometimes just doing @my_record = Model.new and then testing methods > and things like that does the trick (so long as they don't need to be > saved to work). I agree that many tests do not need data in the database. But let me narrow the scope a bit: rutema (shameless plug: http://patir.rubyforge.org/rutema/) essentially lets you execute tests (automated or not) - we're talking about testing a test tool, funny that! All the results end up in a database. It's a straightforward affair (still - you never know). The schema is simple, but we're talking about *a lot* of records. The idea is to leverage all that accumulated data and do something usefull such as detect intermitent failures, spot problematic test scenarios, find which tests where ran against specific software versions etc. and then produce reports on it (yes, yes, ruport is a perfect fit) Essentially I am developing the various views on the data using my tests and I want data to do this. The easiest way is(was) to create that data, put it in the database and start doing different queries on them. I've got my reserves about mocking for this purpose. Fixtures present an easy way to load and unload the database and being lazy I thought to do it once and use that same data for feeding other tests as well. Having said that I find the whole fixtures criticism valid and I agree on most (if not all) points. I guess going with the model-in-memory approach( Run.new({:all_the_data=>like_this}) is the cleaner solution in this case. Yep, the more I think about it the more I like it :) Now to get those tests kitted up! Cheers, V.- P.S. out of academic curiosity I would still like to know why that fixture using code is not working. -- http://www.braveworld.net/riva