Minimal but very flexible implementation of the expect pattern
