import re


def mk_rule_fn(rule, name):
    """Test helper for converting camelCase names to
       underscore_function_names and returning a callable rule fn."""

    parts = re.sub('(?!^)([A-Z][a-z]+)', r' \1', name).split()
    parts.insert(0, 'with')
    fn_name = '_'.join(map(lambda x: x.lower(), parts))
    return getattr(rule, fn_name)