Test fixture syntax

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

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).

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).

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 forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs