DZone 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

Snippets has posted 5883 posts at DZone. View Full User Profile

Load All Fixtures

01.18.2008
| 4720 views |
  • submit to reddit
        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

Justin Mecham replied on Fri, 2008/01/18 - 3:18pm

If you are using Rails 2.0 you can just use "fixtures :all" instead.