Fork me on GitHub
#testing
<
2023-10-06
>
Ingy döt Net17:10:57

Can anyone see the difference here?

expected: {:pairs [{:Sym nil} {:Sym nil}]}
  actual: {:pairs [{:Sym nil} {:Sym nil}]}
    diff: - {:pairs [{:Sym nil} {:Sym nil}]}
          + {:pairs [{:Sym nil} {:Sym nil}]}

Ingy döt Net17:10:55

It's a bit of a trick question, but took me a while to figure out...

Ingy döt Net17:10:14

In "actual", nil is a symbol and in "expected" it is a nil value.

Ingy döt Net17:10:08

The real test was much bigger structure. Thought I was going blind...

Ingy döt Net17:10:40

Might be something for pjstadig.humane-test-output to consider.

dharrigan19:10:45

Does anyone have any recommendations for testing if a function is called (as part of another function being tested) - not caring what it returns or what parameters it takes. Akin to the 'provided' form for midje, but not using midje?

dharrigan19:10:58

For example, I've stumbled upon this

dharrigan19:10:53

Perhaps this looks promising too

dharrigan19:10:13

actually spy works pretty darn well. it'll do 🙂

1
dharrigan19:10:38

thank you,will have a look. Seems like I'm spoilt for choice! 🙂

👍 1
seancorfield20:10:38

Expectations has side-effects for this.

Noah Bogart20:10:27

If you don't mind, what's the value for such a call? Seems like a recipe for annoyance down the line if the implementation changes

dharrigan20:10:21

@U04V70XH6 thank you, will check that out too 🙂

dharrigan20:10:21

Noah, there's a function that is called and in that function it determines if an email is sent or not. It's pretty opaque, but I want to check that the function that sends the email is not called (or is called depending on what happens surrounding it)

👍 1
Noah Bogart20:10:22

In these cases, i've typically done with-redefs for the target function and then in the impl store some value from the call in a local atom, and then assert on the contents of the atom

seancorfield20:10:46

I think that's what a lot of these libs do under the hood?

dharrigan20:10:52

Yup, including side-effects 🙂

Noah Bogart20:10:57

ah yeah, that's probably true

Noah Bogart20:10:20

should have assumed as much!

dharrigan20:10:37

I'm going to try out side-effects tomorrow.

seancorfield20:10:00

But to me it screams: refactor so the email-sending-fn is a parameter or part of a "system" passed in as an argument 🙂 (but that's a general side-effect-y thing -- and I don't follow my own advice on that anyway 😞 )

😅 2
dharrigan20:10:13

Oh, certainly, refactor++

dharrigan20:10:30

But time is pressing and I've made a note to come back and revisit it later

dharrigan20:10:38

and yes, will probably pass the email function in 😉

dharrigan20:10:17

but so far, all my tests now pass. I've just refactored a 2,200 line midje test namespace to clojure test and expectations

😮 1
💯 1
1
dharrigan20:10:20

and I'm tired

dharrigan20:10:46

time for bed and decompression 🙂

dharrigan21:10:32

thank you 🙂 ttfn!

Phillip Mates11:10:15

mockfn was inspired by midje's provided but tries to keep it simple (no metaconstants and isn't tied to a test framework) mockfn was inspired by the

👍 1