spec_helper: refactor a bit get_connection

Get rid of some duplicated code in get_connection
Merge pull request #59 from rsim/refactor-get-connection-in-spec-helper

spec_helper: refactor get_connection to avoid some code duplication