As mentioned
in the documentation, `assert_raise/3` in all its glory allows us to supply a `message` as a `String` or even as a `Regex`.
I personally have a preference to abstract away from specific message content in my tests as tests should not fail on account
of an update to the grammar/phrasal of a given error message.
To illustrate with a practical example, instead of writing a test like this:
test "Required presence `Feature`-token" do
assert_raise(SyntaxError, "Missing `Feature`-token", fn ->
"""
#language:en
"""
|> parse
end)
end
One could instead abstract away as follows:
test "Required presence `Feature`-token" do
assert_raise(SyntaxError, :missing_feature_token, fn ->
"""
#language:en
"""
|> parse
end)
end
That one `error_code` `:missing_feature_token` essentially summarizes the entire error message I may wish to benevolently display to the end-user-in-agony,
which may be a short phrase or even a concise paragraph. Whatever may be, none of that prose needs to leak inside the dark corners of my test suite and an 'error code'
seems to be very helpful to achieve this objective.
My suggestion, if it deems your approval, would require:
- Introduction of `error_code`(or whatever is semantically more sane) inside the relevant defexception
- Modification of def assert_raise
Above, I have volunteered my suggestion in the context of a practical need which happens to be fulfilled by resorting to an `error_code` as an `atom`.
I have a limited imagination, so I hope that others can help explore/share better alternatives.