Thank you very much for your proposal! It seems like you are not at all interested in the actual output of MyModule.my_func(123) in your example. In cases like these, the convention in Elixir is usually to return `true` or `:ok`. These could than be asserted in the test, just like normal:
assert MyModule.my_func(123) == :ok In cases like these, above test is stronger than anything you could test using `refute_raise`. I can see one problem where assert becomes slightly less practical, which would be when `MyModule.my_func` returns an unpredictable value (such as a random number). However, even in these cases we can use `assert` to check if the output: - has the type we expect by using functions like `assert is_integer(myModule.my_func(123))` - matches one of the possible results using `assert MyModule.my_func(123) in [:foo, :bar, :baz]` etc. Of course, non-deterministic tests are bad because when they fail it is hard to reproduce a failure, but that is probably a topic for another conversation. In summary: I do not think that `refute_raise` is useful, since we can easily write more specific tests that will cover all cases that `refute_raise` would cover. Sincerely, ~Wiebe-Marten/Qqwy On Friday, August 12, 2016 at 2:16:52 AM UTC+2, [email protected] wrote: > > Hello, > > Please provide a new refute_raise() assertion in ExUnit so that I can > assert > that no exception was raised when a given function is called. > > At present, the lack of refute_raise() makes some of my test cases look > weird > because they just call a function and don't explicitly assert anything: > > ## a normal looking test case ## > test "should raise when floating point number is given" do > assert_raise ArgumentError, fn -> > MyModule.my_func(123.456) > end > end > > ## a weird looking test case ## > test "should not raise any error when integer is given" do > MyModule.my_func(123) # <== looks weird; what is this asserting? > end > > This is also similar in principle to the existing refute_receive() > assertion. > > Thanks for your consideration. > > -- 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/c1dfdff8-4121-4b5b-8970-1ee8d1e0a697%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
