Fork me on GitHub

Just getting started with testing. Could someone please give me some pointers on this simple test:

(defn deal-card-to-player*
  "Take a card from the deck and add it to the player's hand"
  [state-map deck-id player-id card-ident]
  (-> state-map
    (give-card-to-player* ,,, player-id card-ident)
    (take-from-deck* ,,, deck-id card-ident)))

(specification "Mutation Helpers"
  (component "High level - Abstract actions like dealing, which act on multiple things"
    (behavior "Deals a card from the deck to the player"
        (give-card-to-player* state-map player-id card-ident)
        =1x=> (do
                  state-map => {:x 41}
                  player-id => 1
                  card-ident => [:card/id "h2"])
                {:x 42})
        (take-from-deck* state-map deck-id card-ident)
        =1x=> (do
                  state-map => {:x 42}
                  deck-id => 1
                  card-ident => [:card/id "h2"])
                {:x 43})
          "Calls each mutation helper once"
            ; mocked state-map, values don't matter, just asserting calls and
            ; transformations in the stabby macro
            {:x 41}
            [:card/id "h2"]) => {:x 43})))))


If you’re going to do mocking, you should use guardrails and spec your functions so that the mocking system can verify your “hooking things up” correctly. See when-mocking! , Fulcro guardrails, and my testing video on youtube (Clj West talk). In other words: Your comment that “stat map values don’t matter” isn’t completely true. The value does not matter, but the shape and types of data do. Then there’s commentary on how to spec these, since you’re passing a big map of state. I’d just mention what each function requires (i.e. take-from-deck just needs to see a deck in there).


Thank you. I've started integrating guardrails into my code and workflow. I do wonder how I might get the results in vim as I'm coding, but that's a question for another place. The tip about specifying what must be present in the big state map is helpful too, and seems obvious in retrospect.