lpil / gleeunit

Gleam bindings for the Erlang EUnit test framework
Apache License 2.0
23 stars 17 forks source link

`should.be_ok` and `should.be_error` also unwrap the result #13

Closed massivefermion closed 1 year ago

massivefermion commented 1 year ago

Right now, if we want to test whether a result is Ok and also check the value, this is what we have to do:

pub fn mock_test() {
  process()
  |> should.equal(Ok(correct_result))
}

which is fine, but imagine the following scenario:

pub fn mock_test() {
  process()
  |> should.equal(Ok(2 * base_value * { 1 - ratio }))
}

With this change, I think we could make it a bit cleaner:

pub fn mock_test() {
  process()
  |> should.be_ok
  |> should.equal(2 * base_value * { 1 - ratio })
}

The same with should.be_error.

There is also the fact that in my experience, people are just not using should.be_ok and should.be_error because they usually need to also check the inner value.

lpil commented 1 year ago

Mind updating the changelog? Thank you

massivefermion commented 1 year ago

I updated the changelog, but I wasn't sure about the version, so let me know if you think it should be changed.