Hugh Sasse Staff Elec Eng <hgs / dmu.ac.uk> writes:

> My_class's instance variables are not all "attr :<name>" type variables,
> so some can only be accessed from inside the class.  That is fine, it is
> what OO is all about.

Encapsulation is good.

> It seems like 1 is the only sensible way to do this, and "If the
> errors don't localise the bugs, then Tough!". Is such a question too
> case-specific to have any useful general answer(s)?

I wouldn't put it so negatively. Instead say: all that matters about
my class is its external interface. Therefore, the first and most
basic thing I must test is that interface. Do that.

Then form an opinion. Are those tests revealing a multitude of
internal bugs that are proving difficult to find because you only know 
that the external test fails? I'd suspect not. However, if I'm wrong,
then you have a couple of options when it comes to increasing the
scope of your testing:

1. Produce a subclass of your main class with accessors for the
   internal state and private functions (remember, you can override
   scope in a subclass in Ruby).

2. Refactor your main class. If you really are finding these kind of
   errors, then perhaps your main class is too complex. Maybe it should 
   be refactored, allowing you to write tests for the refactored-out
   helper classes.

However, I suspect that if you take the "don't do it until you need
it" approach, you'll find that you won't need it. In any case, I would 
personally fight against breaking encapsulation just so I could
test. Instead, I'd treat it as being a symptom of some deeper issue.

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

Not knowing the details, it's difficult to be specific, but perhaps an 
initial refactoring might involve separating the data storage (the
interacting hashes, arrays etc) from the file reading.


Regards


Dave