# Load fixtures

**URL:** <https://www.ruby-forum.com/t/load-fixtures/94614>\
**Category:** Rails\
**Created:** [May 9, 2006, 4:25am UTC](https://www.ruby-forum.com/t/load-fixtures/94614 "2006-05-09T04:25:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/35a633/32.png) [@Kian](https://www.ruby-forum.com/u/Kian)\
**Post date:** [May 9, 2006, 4:25am UTC](https://www.ruby-forum.com/t/load-fixtures/94614/1 "2006-05-09T04:25:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Kian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/35a633/32.png) [@Kian](https://www.ruby-forum.com/u/Kian)\
**Post date:** [May 9, 2006, 5:43am UTC](https://www.ruby-forum.com/t/load-fixtures/94614/2 "2006-05-09T05:43:41Z")

</div>

On 5/8/06, Kian [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 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](http://dev.rubyonrails.org/ticket/4742)

---

<div class="post-metadata">

**Author:** ![Kian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/35a633/32.png) [@Kian](https://www.ruby-forum.com/u/Kian)\
**Post date:** [May 10, 2006, 2:07am UTC](https://www.ruby-forum.com/t/load-fixtures/94614/3 "2006-05-10T02:07:31Z")

</div>

Wilson B. \<wilsonb@…\> writes:

> 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](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](http://dev.rubyonrails.org/ticket/1911). Hopefully 1.1.3 will beef up  
support for  
fixtures.

Any suggestions?
