Forum: Ruby on Rails Test fixture syntax

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Steve C. (Guest)
on 2006-04-26 19:21
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
Alex Y. (Guest)
on 2006-04-26 19:38
(Received via mailing list)
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).
Steve C. (Guest)
on 2006-04-26 21:01
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).
Owen Stenseth (Guest)
on 2006-04-26 22:05
(Received via mailing list)
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
This topic is locked and can not be replied to.