Metaconstants and vectors

15 views
Skip to the first unread message

Tom Parker

unread,
7 Feb 2016, 14:43:3207/02/2016
to Midje
I've been having some problems with a "provided" statement and I was wondering if anyone could help? What I want to do is make sure that two values in the called parameters match each other. They will vary from run to run as they're a generated UUID in a string, but they should always be the same in a single run. Relatedly, I'd love to be able to write something where I could retrieve the values from one "provided" function and make sure they match the internal values used at a later call. Was considering something really crufty with atoms, but hope there's a better way.

I tried just writing it out (full version at the bottom of the email), and it didn't work, so I've got a simplified form here that also doesn't work and wanted to check if I'm doing something really stupid...

The provided statement is:

(provided
        (#'clj-leveldb/put anything :conventions ..uuid..)=> nil)

and I get the following errors

FAIL at (handler_tests.clj:33)
You never said #'put would be called with these arguments:
    [nil :conventions ["d0d98d3c-93c1-4a58-b9cf-5b94df02af2a"]]

FAIL at (handler_tests.clj:33)
These calls were not made the right number of times:
    ((var clj-leveldb/put) anything :conventions ..uuid..) [expected at least once, actually never called]

I've tried replacing "..uuid.." with "[..uuid..]", same result. 

FYI, the statement I was trying for at the end is the following 

(provided
        (#'clj-leveldb/put anything :conventions [..uuid..] ..uuid.. {:name "stuff" :from "dd" :to "blah"})=> nil)

Thanks muchly,

Tom Parker

Brian Marick

unread,
7 Feb 2016, 18:34:5707/02/2016
to mi...@googlegroups.com
Not certain I understand your question, but a solution might be to mock out the `get-uuid` function. (That would be akin to the common practice of mocking out `time/now`.) Then your `provided` statement would look something like:

(provided
(get-uuid) => ..uuid..
(subject/place-that-uses-uuid-twice ..uuid.. [..uuid..]) => ...
(subject/a-place-that-needs-the-same-uuid ..uuid..) => 12)
> --
> You received this message because you are subscribed to the Google
> Groups "Midje" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to midje+un...@googlegroups.com
> <mailto:midje+un...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.

Tom Parker

unread,
8 Feb 2016, 05:43:4208/02/2016
to mi...@googlegroups.com
On Sun, 7 Feb 2016 at 23:34 Brian Marick <mar...@exampler.com> wrote:
Not certain I understand your question, but a solution might be to mock out the `get-uuid` function. (That would be akin to the common practice of mocking out `time/now`.) Then your `provided` statement would look something like:

    (provided
       (get-uuid) => ..uuid..
       (subject/place-that-uses-uuid-twice ..uuid.. [..uuid..]) => ...
       (subject/a-place-that-needs-the-same-uuid ..uuid..) => 12)

Sorry, it was a bit rambling. Wasn't quite sure how to phrase it. Your solution gave me the hints I needed to find something that works (replace direct call to java.util.UUID/randomUUID with a function and add a new "provided" line), but I'm still wondering if the original idea would work.

Namely: I have a function for a "provided" line, that has output in a particular form, such that two sub-parts of the output are equal. e.g, simplest form would be 

(provided
   (some-func) => {:foo ..meta.. :bar ..meta.. }
)

I can just add another "provided" bit to override whatever generates ..meta..'s value, but I wonder if it's possible to do that without? In other words, the constraint on ..meta.. is simply that both of the places it's mentioned are equal, and that's all I want to check.

Thanks,

Tom

Brian Marick

unread,
19 Feb 2016, 18:59:0919/02/2016
to mi...@googlegroups.com
Still don't understand, but note that metaconstants only guarantee one thing: that two metaconstants with the same name are `=`. So comparisons of structures that include metaconstants should work as expected.
Reply all
Reply to author
Forward
0 new messages