[#415] Add general-purpose assertion helpers to Morley.Nettest
Description
These were some of the design choices I made, feedback is very much welcome:
-
We will eventually need to add assertions for collections (like the ones in
hspec-expectations
) to facilitate working withMorleyLogs
. I didn't add them yet, because we're not yet sure what the API will look like. So I propose doing this only after/during #461 (closed). -
I named the equality operators
@==
/@/=
.persistent-test
seems to use the same symbols, but I think it's extremely unlikelypersistent-test
andcleveland
will ever be used in the same module, so clashing operator names shouldn't be a problem here. -
@==
/@/=
/checkCompares
useShow
to display the values. I wasn't too sure whether to useShow
orBuildable
, but ended up going withShow
because, in my opinion:- The output of
Show
has the advantage of being copy-pastable back into source code. - I would think
Buildable
is more suitable for applications to display nicely formatted data to the end-user (CLI apps, GUI apps, etc) and Show is more suitable for debugging/testing. - There are more types with
Show
instances than types withBuildable
instances. - I'm pretty sure I've bumped into scenarios where two different values displayed the same string using
pretty
, but would have displayed different strings usingshow
. I can't remember the specific type, sorry:confused:
In any case, I also added
checkComparesWith
for versatility. If necessary, we could also export aPretty
newtype withinstance Show where show = pretty
for convenience (similar to this). - The output of
-
I'm not 100% sure I like the name
checkCompares
. I really wanted to call itshouldCompare
, but using theshould*
prefix means later, when we add the collection assertions, we'll need to call themshouldContain
/shoudNotContain
, etc. These names will clash withhspec-expectations
, which means we'll need to use them qualified. There's a good chance we'll want to usehspec-expectations
andcleveland
in the same module, and we'll want to use both unqualified, so I think avoiding name clashes is important.I ended up using the
check*
prefix, which we already use forcheckBalance
/checkStorage
.checkCompares
andcheckContains
sounds good. The negativecheckNotContains
sounds a bit weird😩 but it's not a big deal, I think.Other possible prefixes:
assert*
,expect*
,must*
. IMO, none of these are a clear improvement overcheck*
, at least not enough that would justify renaming the existingcheckBalance/Storage
functions.
Related issue(s)
Resolves #415 (closed)
✅ Checklist for your Merge Request
Related changes (conditional)
-
Tests (see short guidelines)
-
If I added new functionality, I added tests covering it. -
If I fixed a bug, I added a regression test to prevent the bug from silently reappearing again.
-
-
Documentation
Stylistic guide (mandatory)
-
My commits comply with the following policy. -
My code complies with the style guide.