From: Hugh Sasse Staff Elec Eng Date: 2000-08-18T17:51:55+01:00 Subject: [ruby-talk:04503] RubyUnit and encapsulation. My_class's instance variables are not all "attr :" type variables, so some can only be accessed from inside the class. That is fine, it is what OO is all about. I design some RubyUnit tests for My_class, with a Testing_class to do them. I have 3 ways I could do this: 1 Test the external interface to My_class only. My tests will outlive any implementation details of My_class, but they won't tell me too much about why they have failed, if they do. 2 Test the internals of the class. I cannot get at these from Testing_class, but if I could I could guarantee that each method of My_class was doing what I intended, even private methods, so I could simplify the testing structure, and localise bugs more easily. 3 Make more of the internals of My_class visible to the outside world This would make 2 easier, but if I change the internals later, then my interface changes. It seems like 1 is the only sensible way to do this, and "If the errors don't localise the bugs, then Tough!". The implication seems to be that I should redesign my class, but in what way(s)? My class currently holds arrays, hashes, and booleans in a unified whole. Most of the methos setup the correct values in these as files are processed. Is such a question too case-specific to have any useful general answer(s)? Hugh hgs@dmu.ac.uk