Rspec testing and refactoring