I think `/\n\Z/` might be a better regexp, as that will only remove a newline at the end of the string instead of at the end of (every) line.

I agree that a test would be good to have for this, though.