Tests doesn't clear my tables?

Hi all. I’m using the following test:

[category_test.rb]
require File.dirname(FILE) + ‘/…/test_helper’

class CategoryTest < Test::Unit::TestCase
fixtures :categories
def aequal(expected, got, message=’’)
assert_equal ActiveRecord::Errors.default_error_messages[expected],
got,
message
end

Replace this with your real tests.

def test_no_blank_name
category = Category.create(:name => ‘’)
aequal :blank, category.errors.on(:name), “Empty name”
end

def test_no_nil_name
category = Category.create(:name => nil)
aequal :blank, category.errors.on(:name), “Nil name”
end

def test_no_duplicate_name
category1 = Category.create(:name => “oi”)
category2 = Category.create(:name => “oi”)
aequal :taken, category2.errors.on(:name), “Duplicate name”
end
end
[/category_test.rb]

After call rake test:units, I got:

[output]
$ rake test:units
/usr/bin/rake:17:Warning: require_gem is obsolete. Use gem instead.
(in /home/davi/documentos/rails/eoe)
/usr/bin/ruby18 -Ilib:test
“/usr/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake/rake_test_loader.rb”
“test/unit/category_test.rb”
Loaded suite
/usr/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake/rake_test_loader
Started
F…
Finished in 0.120167 seconds.

  1. Failure:
    test_no_blank_name(CategoryTest)
    [./test/unit/category_test.rb:6:in aequal' ./test/unit/category_test.rb:13:intest_no_blank_name’]:
    Empty name.
    <“can’t be blank”> expected but was
    <[“has already been taken”, “can’t be blank”]>.

3 tests, 3 assertions, 1 failures, 0 errors
rake aborted!
Command failed with status (1):
[/usr/bin/ruby18 -Ilib:test "/usr/lib/ruby/…]

(See full trace by running task with --trace)
[/output]

And my tables has the following data:

[output]

select * from categories;
±—±-----+
| id | name |
±—±-----+
| 1 | |
| 2 | |
±—±-----+
2 rows in set (0.00 sec)
[/output]

What am I doing wrong?

Thanks in advice

Davi V.

E-mail: [email protected]
MSN : [email protected]
GTalk : [email protected]
Skype : davi vidal
ICQ : 138815296

Your database support transactions (commit/rollback) ?

Regards,

Rafael Mueller

On 14 Nov 2007, at 13:24, Davi wrote:

±—±-----+
2 rows in set (0.00 sec)
[/output]

What am I doing wrong?

I’ll ask the obvious question: what’s in your categories.yml file ?

Fred

Em Qua 14 Nov 2007, Davi escreveu:

Hi all. I’m using the following test:

[category_test.rb]
require File.dirname(FILE) + ‘/…/test_helper’

class CategoryTest < Test::Unit::TestCase
fixtures :categories
[…]
end
[/category_test.rb]

What am I doing wrong?

I hadn’t configured my fixtures file.

Sorry my mistake.

–
Davi V.

E-mail: [email protected]
MSN : [email protected]
GTalk : [email protected]
Skype : davi vidal
ICQ : 138815296

Em Qua 14 Nov 2007, Frederick C. escreveu:

What am I doing wrong?

I’ll ask the obvious question: what’s in your categories.yml file ?

categories.yml = fixtures? If yes, I’ve forgotten categories.yml.
Sorry.

Thank you very much.

–
Davi V.

E-mail: [email protected]
MSN : [email protected]
GTalk : [email protected]
Skype : davi vidal
ICQ : 138815296