At present, the only way to easily load a fixture in to a TestUnit is with the "fixtures" class method. While convenient, this method assumes several things about your tests that may not be true; for example, that you have only one set of fixture data per table for the entire application.
Rather than introduce backwards incompatibilities to the 'fixtures' method, this patch introduces a new "fixture" class method that will give developers more flexibility if necessary. For example:
class MixSingularAndPluralFixturesTest < Test::Unit::TestCase
fixtures :topics, :developers, :accounts
fixture :additional_topics, :table_name => "topics", :file_name => "topics2"
...
end
In order to accomplish this, a class called FixtureGroup has been created to represent the idea of a "group" of fixtures. So, for example, the "fixtures" class method above is creating three fixture groups named "topics", "developers" and "accounts". These groups then use sensible defaults to set their class names, table names and fixture file names.
When the developer needs to control these attributes at a finer level, she can choose to use the "fixture" class method. Like the 'fixtures' method, 'fixture' will assume settings appropriately, but only if attributes are not set. For example, the following line would assume the 'accounts' table and the Account class name, but would load a separate yaml file instead of the default "accounts.yml":
fixture :accounts, :file_name => "accounts_in_process"
Additionally, multiple fixture files can be loaded in to the same table:
fixture :topics_set_one, :table_name => "topics", :file_name => "topics"
fixture :topics_set_two, :table_name => "topics", :file_name => "topics2"
Each of the above sets of fixtures can be accessed within the test class via @topics_set_one and @topics_set_two. An error will be raised if the data sets overlap (e.g. if both fixture files define a row in the database table with id '5', an insert error will occur).
NOTE: Some tidying and fixing of the fixtures also took place in this patch. The deprecated yaml test was not reporting errors for .yaml files properly. In addition, there is now a "fixture not found" error message when there are NO matching fixtures (rather than causing error after error during unit tests). Finally, some code was re-arranged so that it matches the "class << self" tidy-looking pattern for a group of class methods.