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]: <false> 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

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.

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]: <false> 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)

  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!

>> 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 White 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.