Fix Nullpointer exception in RSpec caused by race condition