Remove duplicate code in rspec matchers