Refactored some code in test spec