ruby > thoughts.find_all(&:sfw?).to_blog
 => #<URI::HTTP:0x00001 URL: http://MichaelXavier.net >
ruby > MichaelXavier.info
 =>  [ GitHub , Resume , Email ]
ruby > _

Destroy All Models in DataMapper
03|26|2010 — 0 comments  

Categories: ruby, datamapper

I found when writing a spec helper recently that I should have been destroying all models before each test like Rails would.

Thanks to the awesome DKubb from #datamapper on FreeNode for this tip that should have been obvious to me. In my spec/spec_helpers.rb file, I have added the following configuration option:


                  Spec::Runner.configure do |config|
                    config.before(:all) do
                      DataMapper::Model.descendants.each {|m| m.all.destroy }
                    end
                  end
                  

Make sure that you are working on your _test database of course. You may want to use :each instead of :all depending on your tests. Remember that :each is run before each example, :all for each example group.

Comments Comments RSS Feed

Add Comment

(required)
(required, won't be displayed)

(Use Markdown syntax)