Refactor: Extract common code into an assertion helper