Skip to content

jackfirth/racket-mock

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

racket-mock Build Status codecov Stories in Ready

Mocks for Racket testing.

raco pkg install mock
raco pkg install mock-rackunit # RackUnit integration

Documentation: mock, mock-rackunit

This library defines mocks, which are "fake" implementations of functions that record calls made to them. Two separate packages are provided, the main package mock and the RackUnit checks package mock-rackunit. In standard uses, the mock-rackunit dependency is needed only for test code. For a thorough introduction, see The Mock Guide. For a full API reference, see The Mock Reference.

Example:

(require mock mock/rackunit)

(define/mock (foo)
  ; in test, don't call the real bar
  #:mock bar #:as bar-mock #:with-behavior (const "wow!")
  (bar))

(define (bar) "bam!")

(foo) ; "bam!"

(with-mocks foo
  (foo) ; "wow!"
  (check-mock-num-calls 1 bar-mock))