Expect function copied from phpspec