I''m starting to play around with unit tests for some modifications that I''m making to my install of Typo. I''m following the chapter on testing in the Rails book and for some reason can''t get the "delete" code to work. I''ve created a test_delete method with the following code in it: -------------------------------------------------- def test_delete @gallery.destroy assert_raise(ActiveRecord::RecordNotFound) { Gallery.find(@gallery.id) } end -------------------------------------------------- My understanding is that assert_raise should attempt to capture the ActiveRecord::RecordNotFound exception, however when I run the test, I get this error: -------------------------------------------------- ruby test/unit/gallery_test.rb Loaded suite test/unit/gallery_test Started ..E Finished in 0.197074 seconds. 1) Error: test_update(GalleryTest): ActiveRecord::RecordNotFound: Couldn''t find Gallery with ID=1 /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.12.2/lib/active_record/base .rb:413:in `find'' test/unit/gallery_test.rb:7:in `setup_without_fixtures'' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.12.2/lib/active_record/fixt ures.rb:520:in `setup'' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.12.2/lib/active_record/fixt ures.rb:518:in `setup'' 3 tests, 5 assertions, 0 failures, 1 errors -------------------------------------------------- Why is this test failing? I don''t understand what I''ve done wrong. Kyle Heon kheon-Wuw85uim5zDR7s880joybQ@public.gmane.org
Just guessing, but how is your test_helper.rb configured? Have you tried "swapping" transactional and instantiated true/false values? On Nov 4, 2005, at 5:25 PM, Kyle Heon wrote:> I''m starting to play around with unit tests for some modifications > that I''m > making to my install of Typo. I''m following the chapter on testing > in the > Rails book and for some reason can''t get the "delete" code to work. > > I''ve created a test_delete method with the following code in it: > > -------------------------------------------------- > def test_delete > @gallery.destroy > assert_raise(ActiveRecord::RecordNotFound) { Gallery.find > (@gallery.id) } > end > -------------------------------------------------- > > My understanding is that assert_raise should attempt to capture the > ActiveRecord::RecordNotFound exception, however when I run the > test, I get > this error: > > -------------------------------------------------- > ruby test/unit/gallery_test.rb > Loaded suite test/unit/gallery_test > Started > ..E > Finished in 0.197074 seconds. > > 1) Error: > test_update(GalleryTest): > ActiveRecord::RecordNotFound: Couldn''t find Gallery with ID=1 > > /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.12.2/lib/ > active_record/base > .rb:413:in `find'' > test/unit/gallery_test.rb:7:in `setup_without_fixtures'' > > /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.12.2/lib/ > active_record/fixt > ures.rb:520:in `setup'' > > /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.12.2/lib/ > active_record/fixt > ures.rb:518:in `setup'' > > 3 tests, 5 assertions, 0 failures, 1 errors > -------------------------------------------------- > > Why is this test failing? I don''t understand what I''ve done wrong. > > Kyle Heon > kheon-Wuw85uim5zDR7s880joybQ@public.gmane.org > > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Interesting. Here is what my test_helper.rb file looked like (just the important piece): -------------------------------------------------- class Test::Unit::TestCase # Turn off transactional fixtures if you''re working with MyISAM tables in MySQL self.use_transactional_fixtures = true # Instantiated fixtures are slow, but give you @david where you otherwise would need people(:david) self.use_instantiated_fixtures = false -------------------------------------------------- If I comment both of those lines out the tests work. If I comment just the top line, the tests work. If I comment just the bottom line, the tests fail. What does that mean and what should I do to be able to run my tests while taking advantage of the Rails 1.0 performance improvements? For reference, my test looks like this: -------------------------------------------------- def test_delete @gallery.destroy assert_raise(ActiveRecord::RecordNotFound) { Gallery.find(@gallery.id) } end -------------------------------------------------- Any help is greatly appreciated. Thanks! Kyle Heon kheon-Wuw85uim5zDR7s880joybQ@public.gmane.org -----Original Message----- From: Joshua Paul [mailto:joshpaul-ee4meeAH724@public.gmane.org] Sent: Friday, November 04, 2005 8:32 PM To: kheon-Wuw85uim5zDR7s880joybQ@public.gmane.org; rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: Re: [Rails] Unit test error, need clarification Just guessing, but how is your test_helper.rb configured? Have you tried "swapping" transactional and instantiated true/false values? On Nov 4, 2005, at 5:25 PM, Kyle Heon wrote:> I''m starting to play around with unit tests for some modifications > that I''m making to my install of Typo. I''m following the chapter on > testing in the Rails book and for some reason can''t get the "delete" > code to work. > > I''ve created a test_delete method with the following code in it: > > -------------------------------------------------- > def test_delete > @gallery.destroy > assert_raise(ActiveRecord::RecordNotFound) { Gallery.find > (@gallery.id) } > end > -------------------------------------------------- > > My understanding is that assert_raise should attempt to capture the > ActiveRecord::RecordNotFound exception, however when I run the test, I > get this error: > > -------------------------------------------------- > ruby test/unit/gallery_test.rb > Loaded suite test/unit/gallery_test > Started > ..E > Finished in 0.197074 seconds. > > 1) Error: > test_update(GalleryTest): > ActiveRecord::RecordNotFound: Couldn''t find Gallery with ID=1 > > /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.12.2/lib/ > active_record/base > .rb:413:in `find'' > test/unit/gallery_test.rb:7:in `setup_without_fixtures'' > > /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.12.2/lib/ > active_record/fixt > ures.rb:520:in `setup'' > > /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.12.2/lib/ > active_record/fixt > ures.rb:518:in `setup'' > > 3 tests, 5 assertions, 0 failures, 1 errors > -------------------------------------------------- > > Why is this test failing? I don''t understand what I''ve done wrong. > > Kyle Heon > kheon-Wuw85uim5zDR7s880joybQ@public.gmane.org > > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Nov 4, 2005, at 8:53 PM, Kyle Heon wrote:> Interesting. Here is what my test_helper.rb file looked like (just the > important piece): > > -------------------------------------------------- > class Test::Unit::TestCase > # Turn off transactional fixtures if you''re working with MyISAM > tables in > MySQL > self.use_transactional_fixtures = true > > # Instantiated fixtures are slow, but give you @david where you > otherwise > would need people(:david) > self.use_instantiated_fixtures = false > -------------------------------------------------- > > > If I comment both of those lines out the tests work. > If I comment just the top line, the tests work. > If I comment just the bottom line, the tests fail. > > What does that mean and what should I do to be able to run my tests > while > taking advantage of the Rails 1.0 performance improvements? > > For reference, my test looks like this: > > -------------------------------------------------- > def test_delete > @gallery.destroy > assert_raise(ActiveRecord::RecordNotFound) { Gallery.find > (@gallery.id) } > end > -------------------------------------------------- > > Any help is greatly appreciated. Thanks!Hey Kyle, Have you seen the Testing section in the 1.0 upgrade guide? http://manuals.rubyonrails.org/read/chapter/118#page319 It covers the changes in unit testing. Particularly, you want to use galleries(:gallery_name) rather than @gallery_name. jeremy -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (Darwin) iD8DBQFDbE1CAQHALep9HFYRAkpUAJ9/yi3LeaNjsenjyvs9eIuG7yxUlwCfQHxk 70kQtZP06z1v2kTztcTwgLk=4SaH -----END PGP SIGNATURE-----