Given that:
- Testing private methods is not a good practice.
- An interface with many public methods is not a good practice either.
Suppose I have the following code:
module RedisHelper
private
def key_for(id)
[prefix, id].join('-')
end
def prefix
self.class.name.split('::').last.underscore
end
end
class X
include RedisHelper
def perform(id)
key = key_for(id)
redis.sadd(key, [:bar])
end
end
class Y
include RedisHelper
def perform(id)
key = key_for(id)
redis.set(key, :foo)
end
end
What would be the best way to test the behavior of key_for
/prefix
methods without overtesting them? I wouldn't like to repeat its logic when testing classes X
and Y
.
I don't think that turning RedisHelper
's methods public is good, because they would be public in X
and Y
also.