# Test fixture syntax

**URL:** <https://www.ruby-forum.com/t/test-fixture-syntax/58861>\
**Category:** Rails\
**Created:** [April 26, 2006, 5:21pm UTC](https://www.ruby-forum.com/t/test-fixture-syntax/58861 "2006-04-26T17:21:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![scrozier](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/48db29/32.png) [@scrozier](https://www.ruby-forum.com/u/scrozier)\
**Post date:** [April 26, 2006, 5:21pm UTC](https://www.ruby-forum.com/t/test-fixture-syntax/58861/1 "2006-04-26T17:21:06Z")

</div>

OK, I know I’m doing something bone-headed, but I can’t for the life of  
me figure it out.

I’ve read the test fixtures Rdoc about eight dozen times, and it says  
(to me) that if I have a YAML fixture file, dogs.yml that looks like  
this:

fido:  
id: 1  
breed: Terrier  
fifi:  
id: 2  
breed: Poodle

Then I can include

fixtures :dogs

in my functional test, and I’ll have access to a Hash of the model  
objects in the instance variable @dogs. And further, that the fixture  
records are “found” and loaded into instance variables named as the  
fixture. That is, I can also access @fido, and @fido = @dogs[“fido”].

However, I am getting no @dogs at all. I do get dogs (local variable),  
but no @dogs. And I get no @fido or @fifi either.

My error? Doc error? Help!

Thanks,

Steve

---

<div class="post-metadata">

**Author:** ![scrozier](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/48db29/32.png) [@scrozier](https://www.ruby-forum.com/u/scrozier)\
**Post date:** [April 26, 2006, 5:38pm UTC](https://www.ruby-forum.com/t/test-fixture-syntax/58861/2 "2006-04-26T17:38:57Z")

</div>

Steve Crozier wrote:

> fifi:  
> fixture. That is, I can also access @fido, and @fido = @dogs[“fido”].
> 
> However, I am getting no @dogs at all. I do get dogs (local variable),  
> but no @dogs. And I get no @fido or @fifi either.
> 
> My error? Doc error? Help!  
> Doc error. Kind of. There’s a setting called  
> self.use\_instanciated\_fixtures in test\_helper.rb that controls whether  
> the @dogs[:foo] syntax works. As of 1.0, it’s off by default. Instead,  
> you can use the syntax dogs(:foo).

---

<div class="post-metadata">

**Author:** ![scrozier](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/48db29/32.png) [@scrozier](https://www.ruby-forum.com/u/scrozier)\
**Post date:** [April 26, 2006, 7:01pm UTC](https://www.ruby-forum.com/t/test-fixture-syntax/58861/3 "2006-04-26T19:01:42Z")

</div>

Thanks, Alex. I had seen that setting, but had interpreted it  
differently. I tried it and it works great.

Steve

Alex Y. wrote:

> Steve Crozier wrote:
> 
> > fifi:  
> > fixture. That is, I can also access @fido, and @fido = @dogs[“fido”].
> > 
> > However, I am getting no @dogs at all. I do get dogs (local variable),  
> > but no @dogs. And I get no @fido or @fifi either.
> > 
> > My error? Doc error? Help!  
> > Doc error. Kind of. There’s a setting called  
> > self.use\_instanciated\_fixtures in test\_helper.rb that controls whether  
> > the @dogs[:foo] syntax works. As of 1.0, it’s off by default. Instead,  
> > you can use the syntax dogs(:foo).

---

<div class="post-metadata">

**Author:** ![scrozier](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/48db29/32.png) [@scrozier](https://www.ruby-forum.com/u/scrozier)\
**Post date:** [April 26, 2006, 8:05pm UTC](https://www.ruby-forum.com/t/test-fixture-syntax/58861/4 "2006-04-26T20:05:20Z")

</div>

Assuming you are using the latest rails you use fido = dogs(‘fido’).

What you are using below from the docs are called instantiated fixtures  
and they are slow (especially when you have lots of them).

See tests/test\_helper.rb to see how to turn them back on if you really  
want to. Otherwise change your tests to get the fixtures as you need  
them as above.

–  
Owen
