I just want to do unit/test, test to creat person data (here are 3 cloumns) into the table "people" of model person. and in model person, there is "def Person.newly_created(args)" method. In fixtures file, there is test1: id: 1 user_id: 1 firstname: test1 lastname: YY test2: id: 2 user_id: 2 firstname: test2 lastname: TT test3: id: 3 user_id: 3 firstname: test3 lastname: ZZ I want to use assert_difference to test creat all data into database. person_test.rb: require File.dirname(__FILE__) + ''/../test_helper'' class PersonTest < Test::Unit::TestCase fixtures :people def test_should_create_person assert_difference Person, :count do assert=Person.newly_created.valid? end end but there is an error: 1) Error: test_should_create_person(PersonTest): ArgumentError: wrong number of arguments (0 for 1) test/unit/person_test.rb:17:in `newly_created'' test/unit/person_test.rb:17:in `test_should_create_person'' D:/kisscafe/config/../lib/authenticated_test_helper.rb:42:in `assert_difference'' test/unit/person_test.rb:16:in `test_should_create_person'' 1 tests, 0 assertions, 0 failures, 1 errors So I don''t know how to fix this problem. Please help!! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
OnRails wrote:> def test_should_create_person > assert_difference Person, :count do > assert=Person.newly_created.valid?assert is a method, and you are assigning something to it..? And, yes, assert_latest can help you, because it can do anything assert_different Model, :count can do, and more. So if you actually need that, you could use assert_latest. -- Phlip http://www.oreilly.com/catalog/9780596510657/ "Test Driven Ajax (on Rails)" assert_xpath, assert_javascript, & assert_ajax --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
---------- Forwarded message ---------- From: OnRails <zzz...-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org> Date: Sep 2, 9:35 pm Subject: about assert_difference problem. help!! To: Ruby on Rails: Talk I just want to do unit/test, test to creat person data (here are 3 cloumns) into the table "people" of model person. and in model person, there is "def Person.newly_created(args)" method. In fixtures file, there is test1: id: 1 user_id: 1 firstname: test1 lastname: YY test2: id: 2 user_id: 2 firstname: test2 lastname: TT test3: id: 3 user_id: 3 firstname: test3 lastname: ZZ I want to use assert_difference to test creat all data into database. person_test.rb: require File.dirname(__FILE__) + ''/../test_helper'' class PersonTest < Test::Unit::TestCase fixtures :people def test_should_create_person assert_difference Person, :count do assert.Person.newly_created.valid? end end but there is an error: 1) Error: test_should_create_person(PersonTest): ArgumentError: wrong number of arguments (0 for 1) test/unit/person_test.rb:17:in `newly_created'' test/unit/person_test.rb:17:in `test_should_create_person'' D:/kisscafe/config/../lib/authenticated_test_helper.rb:42:in `assert_difference'' test/unit/person_test.rb:16:in `test_should_create_person'' 1 tests, 0 assertions, 0 failures, 1 errors So I don''t know how to fix this problem. Please help!! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
rein.henrichs-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Sep-03 06:57 UTC
Re: about assert_difference problem. help!!
You''ve got some bugs in your syntax that you''ll need to take care of before you start worrying assert_difference. Read the api for the method that''s throwing the exception and do some homework. assert_difference isn''t the issue here... Also, neither assert=Person nor assert.Person do what you want to do. I''d suggest reading up on unit tests in Ruby and Rails. Rein On Sep 3, 12:39 am, OnRails <zzz...-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org> wrote:> ---------- Forwarded message ---------- > From: OnRails <zzz...-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org> > Date: Sep 2, 9:35 pm > Subject: about assert_difference problem. help!! > To: Ruby on Rails: Talk > > I just want to do unit/test, test to creat person data (here are 3 > cloumns) into the table > "people" of model person. and in model person, there is "def > Person.newly_created(args)" method. > In fixtures file, there is > test1: > id: 1 > user_id: 1 > firstname: test1 > lastname: YY > test2: > id: 2 > user_id: 2 > firstname: test2 > lastname: TT > test3: > id: 3 > user_id: 3 > firstname: test3 > lastname: ZZ > > I want to use assert_difference to test creat all data into database. > > person_test.rb: > require File.dirname(__FILE__) + ''/../test_helper'' > class PersonTest < Test::Unit::TestCase > fixtures :people > > def test_should_create_person > assert_difference Person, :count do > assert.Person.newly_created.valid? > end > end > > but there is an error: > 1) Error: > test_should_create_person(PersonTest): > ArgumentError: wrong number of arguments (0 for 1) > test/unit/person_test.rb:17:in `newly_created'' > test/unit/person_test.rb:17:in `test_should_create_person'' > D:/kisscafe/config/../lib/authenticated_test_helper.rb:42:in > `assert_difference'' > test/unit/person_test.rb:16:in `test_should_create_person'' > > 1 tests, 0 assertions, 0 failures, 1 errors > > So I don''t know how to fix this problem. Please help!!--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
[Please don''t reply to private e-mail addresses from a public group...] OnRails wrote:> def test_should_create_person > assert_difference Person, :count do > assert.Person.newly_created.valid?What''s with the dot . between assert and Person? Tip: Write almost nothing in your test. Then run rake test:recent and see it pass. Then write the _minimum_ new code into your test that you possibly can. Run test:recent again. Keep repeating until you understand each failure point. Don''t write a whole bunch and wait to test it all. That technique is how experienced programmers write huge programs, too... -- Phlip http://www.oreilly.com/catalog/9780596510657/ "Test Driven Ajax (on Rails)" assert_xpath, assert_javascript, & assert_ajax --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thank you so much, Phlip. I am new learner for test. and you help me so much. I dealed with assert_difference depend on your suggestion. The first time I just used "assert_difference Person, :count do" all the data have inserted database that is I wanted. and second time I want to verify these data, I used "assert.Person.newly_created.valid?", but it is wrong. So could you give me some suggestion about this? Thanks again! On Sep 3, 6:22 am, "Phlip" <phlip2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> [Please don''t reply to private e-mail addresses from a public group...] > > OnRails wrote: > > def test_should_create_person > > assert_difference Person, :count do > > assert.Person.newly_created.valid? > > What''s with the dot . between assert and Person? > > Tip: Write almost nothing in your test. Then run > > rake test:recent > > and see it pass. Then write the _minimum_ new code into your test that you > possibly can. Run test:recent again. Keep repeating until you understand > each failure point. Don''t write a whole bunch and wait to test it all. > > That technique is how experienced programmers write huge programs, too... > > -- > Phlip > http://www.oreilly.com/catalog/9780596510657/ > "Test Driven Ajax (on Rails)" > assert_xpath, assert_javascript, & assert_ajax--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> "assert.Person.newly_created.valid?", but it is wrong.You wrote "assert.Person". There''s a dot between the assert and Person. Use "assert Person"! -- Phlip http://www.oreilly.com/catalog/9780596510657/ "Test Driven Ajax (on Rails)" assert_xpath, assert_javascript, & assert_ajax --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thank you very much, Phlip I got it. Thanks! On Sep 3, 10:52 am, "Phlip" <phlip2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > "assert.Person.newly_created.valid?", but it is wrong. > > You wrote "assert.Person". There''s a dot between the assert and Person. > > Use "assert Person"! > > -- > Phlip > http://www.oreilly.com/catalog/9780596510657/ > "Test Driven Ajax (on Rails)" > assert_xpath, assert_javascript, & assert_ajax--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---