New test helper function to check that we got the error we wanted

This simplifies a bunch of our tests and, again, reduces duplication
same as above.