I’m trying to find a way to fix a design issue where I have some module methods public for the sole purpose of running tests on them.

I have a module that creates a user along with a confirmation token (which is stored in users table field with uniqueness constraint on it) using these steps:

generate a token with the help of EmailConfirmationHandler

merge it with passed user attributes

persist the user

Because the token uniqueness validation happens on a user persisting step, there can be a case when the saving fails and the whole process needs to be repeated with a regenerated token.

My main module has only 1 method call that I want to expose, but in order to test all scenarios properly I need to also test private methods(as I need to check how module performs with different results from EmailConfirmationHandler), hence I change their accessibility level to public.

So the question is, is there a better way to design this functionality so I don’t have any private methods exposed for the sole purpose of testing?

I don’t see you using App.UserCreator functions in your test at all. Based on what you do use in your tests, you can change create_user_with and process_user_creation_result accessibility levels to private.

Off-topic …

I generally try not to mess with attrs and treat it as an opaque data structure, since in my apps they usually come from the user and I can’t trust it, so I do something like this: