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... -- Posted via http://www.ruby-forum.com/.
Dan Tenenbaum
2006-Jan-20 19:05 UTC
[Rails] Re: hash fixture access broken in functional test
Dan Tenenbaum 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.......... -- Posted via http://www.ruby-forum.com/.
Keith Lancaster
2006-Jan-20 20:09 UTC
[Rails] Re: hash fixture access broken in functional test
Dan Tenenbaum wrote:> Dan Tenenbaum 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 -- Posted via http://www.ruby-forum.com/.
Keith Lancaster
2006-Jan-20 20:10 UTC
[Rails] Re: hash fixture access broken in functional test
Keith Lancaster wrote:> Dan Tenenbaum wrote: >> Dan Tenenbaum 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...) -- Posted via http://www.ruby-forum.com/.
Dan Tenenbaum
2006-Jan-20 20:14 UTC
[Rails] Re: hash fixture access broken in functional test
Keith Lancaster wrote:> Things changed just slightly since the book: here is a quote from > http://www.ruby-forum.com/topic/50061#17690Thanks. That works. Hope they come out with that PDF of revisions......... -- Posted via http://www.ruby-forum.com/.