add spec, docs for withStateMachine method