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:in `test_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 Vidal
--
E-mail: davividal-UiHwsRqXctc1RhZgQKG/ig@public.gmane.org
MSN : davividal-uAjRD0nVeow@public.gmane.org
GTalk : davividal-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Skype : davi vidal
ICQ : 138815296
Your database support transactions (commit/rollback) ? Regards, -- Rafael Mueller http://queroseragil.wordpress.com On Nov 14, 2007 10:24 AM, Davi <davividal-UiHwsRqXctc1RhZgQKG/ig@public.gmane.org> wrote:> > 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:in `test_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 Vidal > -- > E-mail: davividal-UiHwsRqXctc1RhZgQKG/ig@public.gmane.org > MSN : davividal-uAjRD0nVeow@public.gmane.org > GTalk : davividal-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > Skype : davi vidal > ICQ : 138815296 >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 14 Nov 2007, at 13:24, Davi wrote:> > 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? >I''ll ask the obvious question: what''s in your categories.yml file ? Fred --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 Vidal -- E-mail: davividal-UiHwsRqXctc1RhZgQKG/ig@public.gmane.org MSN : davividal-uAjRD0nVeow@public.gmane.org GTalk : davividal-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org Skype : davi vidal ICQ : 138815296
Em Qua 14 Nov 2007, Frederick Cheung escreveu:> On 14 Nov 2007, at 13:24, Davi wrote: > > 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? > > 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 Vidal -- E-mail: davividal-UiHwsRqXctc1RhZgQKG/ig@public.gmane.org MSN : davividal-uAjRD0nVeow@public.gmane.org GTalk : davividal-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org Skype : davi vidal ICQ : 138815296