views:

15

answers:

1
class Category < ActiveRecord::Base

  acts_as_tree

end

How to test that acts_as_tree gets called? Or that any other in class body method gets called?

+2  A: 

Why would you want to test that it gets called? Of course it gets called!

What you really should be doing is testing that your application behaves the way you want it to behave. You write test cases illustrating how you want your application to behave, and then you run the test cases to check that the application does indeed behave that way.

You can write test cases checking that Category instances have parents and children, that you can retrieve the list of children given a parent, that you can create a new Category instance and add it to some pre-existing Category instance's list of children, or various other behaviors important to your application.

Justice
Well, you got a good point there. But somehow it still feels more natural for me to test that acts_as_tree method is called inside class rather than test for methods it implements. It's like RSpec testing that a module is included rather than testing for newly included methods...
Mirko