Hash fixture access broken in functional test


#1

I have a functional test class that uses the “topics” fixture. I
verified that the fixture is loaded into the database by doing this:
assert_equal 2, Topic.find_all.size

So I should have an instance variable called @topics and instance
variables for each of the rows in the fixture, in this case, @first and
@another. But all those variables are nil inside my test method.

Is that convenience only available in unit tests? It is equally useful
in functional tests. Or is there some other problem? Thanks…


#2

Dan T. wrote:

I have a functional test class that uses the “topics” fixture. I
verified that the fixture is loaded into the database by doing this:
assert_equal 2, Topic.find_all.size

So I should have an instance variable called @topics and instance
variables for each of the rows in the fixture, in this case, @first and
@another. But all those variables are nil inside my test method.

Is that convenience only available in unit tests? It is equally useful
in functional tests. Or is there some other problem? Thanks…

Looks like this doesn’t work in unit tests either. What gives? The rails
book says I should be able to do this, and I definitely have a more
recent version of rails and ruby than they did when writing that
book…


#3

Dan T. wrote:

Dan T. wrote:

I have a functional test class that uses the “topics” fixture. I
verified that the fixture is loaded into the database by doing this:
assert_equal 2, Topic.find_all.size

So I should have an instance variable called @topics and instance
variables for each of the rows in the fixture, in this case, @first and
@another. But all those variables are nil inside my test method.

Is that convenience only available in unit tests? It is equally useful
in functional tests. Or is there some other problem? Thanks…

Looks like this doesn’t work in unit tests either. What gives? The rails
book says I should be able to do this, and I definitely have a more
recent version of rails and ruby than they did when writing that
book…

Things changed just slightly since the book: here is a quote from
http://www.ruby-forum.com/topic/50061#17690

The book is awesome, but beware that the section on accessing > fixture data in unit tests is broken since 1.0 came around. Found > that out the hard way the other night. > > You used to be able to access fixture data like @my_product, but > now it’s like products(:my_product)

HTH,
Keith


#4

Keith L. wrote:

Dan T. wrote:

Dan T. wrote:

I have a functional test class that uses the “topics” fixture. I
verified that the fixture is loaded into the database by doing this:
assert_equal 2, Topic.find_all.size

So I should have an instance variable called @topics and instance
variables for each of the rows in the fixture, in this case, @first and
@another. But all those variables are nil inside my test method.

Is that convenience only available in unit tests? It is equally useful
in functional tests. Or is there some other problem? Thanks…

Looks like this doesn’t work in unit tests either. What gives? The rails
book says I should be able to do this, and I definitely have a more
recent version of rails and ruby than they did when writing that
book…

Things changed just slightly since the book: here is a quote from
http://www.ruby-forum.com/topic/50061#17690

The book is awesome, but beware that the section on accessing > fixture data in unit tests is broken since 1.0 came around. Found > that out the hard way the other night. > > You used to be able to access fixture data like @my_product, but > now it’s like products(:my_product)

HTH,
Keith

From the same post:
This is simply an option which was on by default and was turned off by
default but it is still a valid way to access fixture data, all you
have to do is change test_helper.rb (if you want it for all tests, or
add the following line at the beginning of the testcase where you want
it :

self.use_instantiated_fixtures = true

Keith (again…)


#5

Keith L. wrote:

Things changed just slightly since the book: here is a quote from
http://www.ruby-forum.com/topic/50061#17690

Thanks. That works. Hope they come out with that PDF of
revisions…