# About assert\_difference problem. help!

**URL:** <https://www.ruby-forum.com/t/about-assert-difference-problem-help/113631>\
**Category:** Rails\
**Created:** [September 3, 2007, 6:36am UTC](https://www.ruby-forum.com/t/about-assert-difference-problem-help/113631 "2007-09-03T06:36:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![OnRails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/51bf81/32.png) [@OnRails](https://www.ruby-forum.com/u/OnRails)\
**Post date:** [September 3, 2007, 6:36am UTC](https://www.ruby-forum.com/t/about-assert-difference-problem-help/113631/1 "2007-09-03T06:36:26Z")

</div>

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!!

---

<div class="post-metadata">

**Author:** ![OnRails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/51bf81/32.png) [@OnRails](https://www.ruby-forum.com/u/OnRails)\
**Post date:** [September 3, 2007, 6:58am UTC](https://www.ruby-forum.com/t/about-assert-difference-problem-help/113631/2 "2007-09-03T06:58:27Z")

</div>

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/](http://www.oreilly.com/catalog/9780596510657/)  
“Test Driven Ajax (on Rails)”  
assert\_xpath, assert\_javascript, & assert\_ajax

---

<div class="post-metadata">

**Author:** ![OnRails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/51bf81/32.png) [@OnRails](https://www.ruby-forum.com/u/OnRails)\
**Post date:** [September 3, 2007, 7:40am UTC](https://www.ruby-forum.com/t/about-assert-difference-problem-help/113631/3 "2007-09-03T07:40:30Z")

</div>

---------- Forwarded message ----------  
From: OnRails [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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!!

---

<div class="post-metadata">

**Author:** ![OnRails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/51bf81/32.png) [@OnRails](https://www.ruby-forum.com/u/OnRails)\
**Post date:** [September 3, 2007, 8:58am UTC](https://www.ruby-forum.com/t/about-assert-difference-problem-help/113631/4 "2007-09-03T08:58:41Z")

</div>

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
