Refactor common code in TestSpecificErrorTypes.

Signed-off-by: Daira Hopwood <daira@leastauthority.com>