spec_helper: refactor a bit get_connection

Get rid of some duplicated code in get_connection