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.
- Failure:
test_no_blank_name(CategoryTest)
[./test/unit/category_test.rb:6:inaequal' ./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