Simple unit test failure

Snipping out unnecessary, /test/unit/personnel_test.rb…

def setup
@first = “Test”
@last = “User”
@new_id = ‘1000’
end

def test_create_read_update_delete
person = Personnel.new(:id => @new_id,
:first_name => @first,
:last_name => @last)

# save him
assert person.save

end

running this test gets me an error…

$ ruby test/unit/personnel_test.rb
Loaded suite test/unit/personnel_test
Started
F.
Finished in 0.39329 seconds.

  1. Failure:
    test_create_read_update_delete(PersonnelTest)
    [test/unit/personnel_test.rb:23]:
    is not true.

2 tests, 4 assertions, 1 failures, 0 errors

The error is on the line… ‘assert person.save’

The only ‘not null’ fields in my personnel table are id (obviously),
first_name and last_name. The personnels table does not have a record
with id = 1000. I can ‘find’ by id items loaded via fixtures but cannot
assert the above save. Is it my syntax? How do I get more information
about the failure (adding -v doesn’t give me meaningful info)

Craig

Craig,

You could look in log/test.log. That file can grow large enough that
it’s a little hard to spot just what you want, though, so I often
delete it before running tests when I need to dig into a test failure.
It’ll be recreated when you run your test and should contain only the
data collected from that test run.

Regards,
Craig

On Sat, 2008-05-24 at 12:46 -0400, Craig D. wrote:

Craig,

You could look in log/test.log. That file can grow large enough that
it’s a little hard to spot just what you want, though, so I often
delete it before running tests when I need to dig into a test failure.
It’ll be recreated when you run your test and should contain only the
data collected from that test run.


I’ve been ‘tailing’ it as I work and it gives me nothing…

$ cat log/test.log
SQL (0.001977) SET search_path TO db
SQL (0.001476) BEGIN
SQL (0.023013) SELECT count() AS count_all FROM personnels
SQL (0.001639) ROLLBACK
SQL (0.000325) BEGIN
SQL (0.002350) SELECT count(
) AS count_all FROM personnels
SQL (0.000546) ROLLBACK

the 'select count(*) are from my ‘teardown’ method

Craig

On Sat, 2008-05-24 at 09:26 -0700, Craig W. wrote:

 :first_name => @first,

Started
The error is on the line… ‘assert person.save’

The only ‘not null’ fields in my personnel table are id (obviously),
first_name and last_name. The personnels table does not have a record
with id = 1000. I can ‘find’ by id items loaded via fixtures but cannot
assert the above save. Is it my syntax? How do I get more information
about the failure (adding -v doesn’t give me meaningful info)


never mind…it was a validation in the model that wasn’t reflected in
the database - fixed

Thanks

Craig

def setup
@first = “Test”
@last = “User”
@new_id = ‘1000’
end

Going forward, you are abusing the setup here. Each test case should
generally use different sample data, so put them in the test case
itself,
and don’t lean on @ variables until they serve a real purpose!

Craig W. wrote:

thanks…I’ve been going though the ‘Guide to Testing the Rails’ on
manuals.rubyonrails.com and ‘Gluttonous’ but it would help to see real
life examples…any suggestions?

The source code to beast is exemplary!

Also, and this is probably big…I use an RBAC method suggested in Rails
Recipes with a self-rolled authentication system against LDAP which
blocks controllers methods. I can only get these tests to run if I
disable the RBAC…any suggestions here?

Use Mocha to make the library return what you need. The point of tests
is not to
promise accuracy, it’s to make sure your code stays the same (bugs and
all) as
you add features.

And to let you Undo, if a test fails unexpectedly, instead of debugging.

On Sat, 2008-05-24 at 10:58 -0700, Phlip wrote:

def setup
@first = “Test”
@last = “User”
@new_id = ‘1000’
end

Going forward, you are abusing the setup here. Each test case should
generally use different sample data, so put them in the test case itself,
and don’t lean on @ variables until they serve a real purpose!


thanks…I’ve been going though the ‘Guide to Testing the Rails’ on
manuals.rubyonrails.com and ‘Gluttonous’ but it would help to see real
life examples…any suggestions?

Also, and this is probably big…I use an RBAC method suggested in Rails
Recipes with a self-rolled authentication system against LDAP which
blocks controllers methods. I can only get these tests to run if I
disable the RBAC…any suggestions here?

Thanks

Craig