I''m finally getting beyond using basic test fixtures, and a few questions have popped up. Has anyone found ways to do these? 1. Use a test fixture that is named differently from its table name? We''d like to have more than one possible fixture per table. (Or perhaps use test fixtures named similarly but in different directories.) 2. Load a test fixture for one test method only in a test file (and not for the other test methods in the source file)? Thought I had a way to do this using Fixtures.create_fixtures and Fixtures.instantiate_fixtures, but it messed up the deleting of other fixtures'' data at the start of the next test method. Thanks, Kian W
On 5/8/06, Kian <kianwright@pfima.com> wrote:> I''m finally getting beyond using basic test fixtures, and a few questions > have popped up. Has anyone found ways to do these? > > 1. Use a test fixture that is named differently from its table name? We''d like > to have more than one possible fixture per table. (Or perhaps use test fixtures > named similarly but in different directories.) > > 2. Load a test fixture for one test method only in a test file (and not for the > other test methods in the source file)? Thought I had a way to do this using > Fixtures.create_fixtures and Fixtures.instantiate_fixtures, but it messed up the > deleting of other fixtures'' data at the start of the next test method.There''s no way to do #1 in the existing fixture code. The closest you can come is by using the new-ish subfolder fixture code. If your table is named ''examples'' ..you can have /test/fixtures/examples.yml be an empty file. Then, in /test/fixtures/examples/, place as many fixtures with any filenames you wish. The drawback is that the fixtures still need to be uniquely named. If you have test/fixtures/examples/group_one.yml and group_two.yml, a fixture named examples(:blah) can only exist in one of them at a time. I did a patch a while ago that changed this, but it hasn''t gotten much love, and may not apply cleanly to the current version. I should probably turn it into a plugin, but it wouldn''t be fun to maintain, given the structure of the fixtures code. You can find it here if you''re interested: http://dev.rubyonrails.org/ticket/4742
Wilson Bilkovich <wilsonb@...> writes:> > There''s no way to do #1 in the existing fixture code. > The closest you can come is by using the new-ish subfolder fixture code. > > If your table is named ''examples'' > ..you can have /test/fixtures/examples.yml be an empty file. > Then, in /test/fixtures/examples/, place as many fixtures with any > filenames you wish. > The drawback is that the fixtures still need to be uniquely named. If > you have test/fixtures/examples/group_one.yml and group_two.yml, a > fixture named examples(:blah) can only exist in one of them at a > time. > > I did a patch a while ago that changed this, but it hasn''t gotten much > love, and may not apply cleanly to the current version. I should > probably turn it into a plugin, but it wouldn''t be fun to maintain, > given the structure of the fixtures code. > > You can find it here if you''re interested: > http://dev.rubyonrails.org/ticket/4742 >Thanks. But it appears that I still have to load all the fixtures in the ''examples'' directory, right? I really want to be able to selectively load only certain fixtures for a given table. I tried ''fixtures "examples/group_one"'', but that fails (something about no table named ''group_one'', which makes sense). I also tried separate subfolders, e.g., ''example1'' and ''example2'', each with a YAML file named after the table. It doesn''t error, but it doesn''t appear to load the fixture either. Wilson''s patch looks interesting; so does the Flexible Fixtures one http://dev.rubyonrails.org/ticket/1911. Hopefully 1.1.3 will beef up support for fixtures. Any suggestions?