Refactor rspec test code