Refactor middleware_spec tests