Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

load all fixtures (See related posts)

In some test cases I need all my fixtures to be loaded. To make this easier, add the following to test/test_helper.rb:

class Test::Unit::TestCase
  def self.all_fixtures
    Dir[File.dirname(__FILE__) + "/fixtures/*.yml"].each do |f|
      fixtures File.basename(f, '.yml')
    end
  end

  ..
end


and in your tests use it as follows:

class FooTest < Test::Unit::TestCase
  all_fixtures

  ..
end


Happy testing!

Comments on this post

jsmecham posts on Jan 18, 2008 at 14:22
If you are using Rails 2.0 you can just use "fixtures :all" instead.

You need to create an account or log in to post comments to this site.


Click here to browse all 4863 code snippets

Related Posts