about assert_difference problem. help!!

O

OnRails Ruby

class PersonTest < Test::Unit::TestCase
fixtures :people
def setup
end

def test_should_create_person
assert_difference people, :count do
person=Person.newly_created
assert !person.new_record?,
"#{person.errors.full_messages.to_sentence}"
end
end
end

people.yml
test1:
id: 1
user_id: 1
firstname: test1
lastname: YY
test2:
id: 2
user_id: 2
firstname: test2
lastname: TT


ruby test\unit\person_test.rb
1) Error:
test_should_create_person(PersonTest):
ArgumentError: wrong number of arguments (0 for 1)
test/unit/person_test.rb:16:in `people'
test/unit/person_test.rb:16:in `test_should_create_person'

1 tests, 0 assertions, 0 failures, 1 errors

I don't know why causeed this proble. who can tell me? Thanks.
 
O

OnRails Ruby

I just want to do unit/test, test to creat person data 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
I want to use assert_difference to test creat all data into database.
and now I modified as blow:
def test_should_create_person
assert_difference Person, :count do
assert=Person.newly_created.valid?
end
end
but there is same 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_differe
nce'
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.

By the way, I have read assert_latest, but I don't think that can
perform my target.
ThanKs, Phlip
 
O

OnRails Ruby

OnRails said:
I just want to do unit/test, test to creat person data 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
I want to use assert_difference to test creat all data into database.
and now I modified as blow:
def test_should_create_person
assert_difference Person, :count do
assert.Person.newly_created.valid?
end
end
but there is same 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_differe
nce'
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.

By the way, I have read assert_latest, but I don't think that can
perform my target.
ThanKs, P

def test_should_create_person
assert_difference Person, :count do
assert.Person.newly_created.valid?
end
end
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,264
Messages
2,571,321
Members
48,004
Latest member
KelseyFors

Latest Threads

Top