Only hook into test/spec tasks if they are defined

Signed-off-by: Alex Coles <alex@alexbcoles.com>