[rspec-users] What should I test/specify?

John Feminella johnf at distb.net
Sat Oct 30 12:47:43 EDT 2010

If you're writing a unit test for a method, the general rule of thumb
is to test what the method itself does. That sounds tautological, but
it's meant to define the boundary of what you should and shouldn't
care about.

In this case, you only care about the fact that `YAML::load_file` is
called, and that `BehaviorTreeCreator.new` is then called with the
result of that, and that *that* result has `create` invoked on it.
That's it: if those three things happen, then this method is working
as you expect.

Your unit tests for BehaviorTreeCreator.new and .create will probably be richer.

~ jf
John Feminella
Principal Consultant, BitsBuilder
LI: http://www.linkedin.com/in/fjsquared
SO: http://stackoverflow.com/users/75170/

More information about the rspec-users mailing list