Forum: Ruby on Rails unit testing methods interfering with each other

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.
1f8a2831a8b45f62eee765c96c67747a?d=identicon&s=25 nmkolev (Guest)
on 2005-12-07 14:56
(Received via mailing list)
Hi all,

I am following the Agile Rails book and have a problem with unit
testing. Here is my products test file:

require File.dirname(__FILE__) + '/../test_helper'

class ProductTest < Test::Unit::TestCase

   fixtures :products

   def setup
     @product = Product.find 1
   end

   def test_load_in_db
     assert_kind_of Product, @product
     assert_equal 29.95, @product.price
   end

   def test_destroy
     @product.destroy
     assert_raise(ActiveRecord::RecordNotFound) { Product.find
@product.id }
   end

end

According to the book this should work, as different tests are not
dependent on each other, e.g. the destroy test should be independent
of the load_in_db test. I do howeveg get this after running the test:

:!ruby test/unit/product_test.rb
Loaded suite test/unit/product_test
Started
.E
Finished in 0.259161 seconds.

   1) Error:
test_load_in_db(ProductTest):
ActiveRecord::RecordNotFound: Couldn't find Product with ID=1
     /opt2/local/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/
active_record/base.rb:428:in `find'
     test/unit/product_test.rb:8:in `setup_without_fixtures'
     /opt2/local/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/
active_record/fixtures.rb:522:in `setup'
     /opt2/local/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/
active_record/fixtures.rb:520:in `setup'

2 tests, 1 assertions, 0 failures, 1 errors

If I remove the destroy test everything works as expected?

Any ideas as to why this is happening?

Many thanks in advance,
Nicky
1f8a2831a8b45f62eee765c96c67747a?d=identicon&s=25 nmkolev (Guest)
on 2005-12-07 15:37
(Received via mailing list)
OK, found it. Has to do with the fact that Rails 0.14 switched to
transactional fixtures which my MySQL table type did not support.
More details here: http://www.clarkware.com/cgi/blosxom/
2005/10/24#Rails10FastTesting

Cheers,
-- Nicky
This topic is locked and can not be replied to.