Fix undefined condition and add spec