Test not Reseting


#1

My test are not resetting for each method in the test class.

It was promised to me on page 146 of Agile Web D. on Rails that
it would.

Am I doing something wrong? The “@delete_victim = User.find(4)” bust
the setup class each time it comes around, even though that is in my
users.yml

class UserTest < Test::Unit::TestCase
fixtures :users

def setup
@chris_logged_in = User.new({:username => ‘cwinslett’, :password
=> ‘testpassword’})
@chris_logged_in = @chris_logged_in.try_to_login
@sherri = User.find(2)
@delete_victim = User.find(4)
end

Replace this with your real tests.

def test_truth
assert_kind_of User, @chris_logged_in
assert_kind_of User, @sherri
assert_kind_of User, @investor
end

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

def test_create_user
@tom_lawyer = User.new
@tom_lawyer.username = “tlawyer”
@tom_lawyer.password = “i<3lawyers”
@tom_lawyer.email = “removed_email_address@domain.invalid”
@tom_lawyer.first_name = “Tom”
@tom_lawyer.last_name = “Lawyer”
assert @tom_lawyer.save, @tom_lawyer.errors.full_messages.join("; ")
@tom_lawyer = User.new({:username => “tlawyer”, :password
=> “i<3lawyers”})
@tom_lawyer = @tom_lawyer.try_to_login
assert_equal “a6e29adca96aac7c85275792c7562e85”,
@tom_lawyer.hashed_password
end
end


#2

Chris W. wrote:

My test are not resetting for each method in the test class.

You’re probably running a DB without transaction support, let me
guess… MySQL on MyISAM tables?

Either move to a DB/table-engine that supports transactions or turn off
transaction-based testing in test/test_helper.rb.