No, that would be overkill. I already check with what MRI does and it seems that they basically check both the string itself and the pattern whether they are valid encodings.

What we need here is have at least more than one encoding. With one encoding, you created an implementation to fix it with a specific exception for that encoding, that is what triggered me into asking these questions. Implementing something that specific for one encoding is something that is nowhere else in the codebase and I also can't imagine MRI implementing any encoding stuff in that way.

So we should at least test this for another encoding, but please consider this. If we want to test for example with UTF-32BE, we can't just force_encoding a UTF-8 encoded string to that. That makes no sense. We have to create a properly value UTF-32BE string for that before we modify it to be an invalid string. You can use String#encode to transcode a string from one encoding into another.

Another thing is that in the spec description we probably need to get rid of UTF-8. That only seems to be causing confusion since there was the assumption that this was somehow UTF-8 specific behavior, while I'm certain this is general encoding behavior and not specific to just a single encoding.