Any perspectives on this proposal? On Friday, December 27, 2019 at 6:59:34 PM UTC-5, Kevin Johnson wrote: > > As mentioned in the documentation > <https://hexdocs.pm/ex_unit/ExUnit.Assertions.html#assert_raise/3>, > `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: > > 1. Introduction of `error_code`(or whatever is semantically more sane) > inside > the relevant defexception > > <https://github.com/elixir-lang/elixir/blob/cd9253d1027bf8c0b0d34cb6ccd98f1a7b872d3e/lib/ex_unit/lib/ex_unit/assertions.ex#L4-L7> > 2. Modification of def assert_raise > > <https://github.com/elixir-lang/elixir/blob/cd9253d1027bf8c0b0d34cb6ccd98f1a7b872d3e/lib/ex_unit/lib/ex_unit/assertions.ex#L377-L435> > > 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. > > >
-- You received this message because you are subscribed to the Google Groups "elixir-lang-core" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/0ff059ca-cf92-4ed9-885c-0b72b89806a2%40googlegroups.com.
