[rspec-users] Module & Mixin testing strategy

Mike Howson lists at ruby-forum.com
Sat Aug 14 06:34:12 EDT 2010


Just wondered what people thoughts are to testing module's to be
included in mixin's? Seems to me there are two main approaches:-

1. Test the behavior in a mixin object that includes the module because
its the behavior of the object thats important not the code structure.

2. Test the module in isolation as it potentially code be included

If the best approach is 2 - to test the module in isolation and the
module uses instance variables or methods from the object its being
mixed with then we would need to create a test object in the rspec test
that included the module and defined the required instance variables and
methods. Does this lead to 1 being the best approach as we are not then
forced to mock up a mixin just to test the module?

The question came about because I recently had to get an untested rails
module under test that was included in a number of controllers and
depended on 'request' and 'response'. I was then faced with either
testing one of the controllers that included that module but also added
further complexity or defining a new thin controller used solely for
testing the module within the spec file.

Interested to know your thoughts!

Posted via http://www.ruby-forum.com/.

More information about the rspec-users mailing list