Mock Rack  Unit Checks
check-mock-calls
check-mock-called-with?
check-mock-num-calls
check-call-history-names
8.12

Mock RackUnit Checks🔗ℹ

 (require mock/rackunit) package: mock-rackunit

This package provides rackunit checks for working with mocks from the mock library.

procedure

(check-mock-calls m args-list)  void?

  m : mock
  args-list : (listof arguments)
A rackunit check that passes if m has been called with each args in their given order and no other times.

Examples:
> (define void-mock (mock #:behavior void))
> (void-mock 1)
> (void-mock 'foo)
> (check-mock-calls void-mock (list (arguments 1)))

--------------------

FAILURE

name:                check-mock-calls

location:            eval:4:0

params:              '(#<procedure:mock> ((arguments 1)))

mock:                #<procedure:mock>

actual-num-calls:    2

expected-num-calls:  1

extra-calls:         ((arguments foo))

Mock called more times than expected

--------------------

> (check-mock-calls void-mock (list (arguments 1) (arguments 'foo)))
> (check-mock-calls void-mock (list (arguments 'foo) (arguments 1)))

--------------------

FAILURE

name:                check-mock-calls

location:            eval:6:0

params:              '(#<procedure:mock> ((arguments foo) (arguments 1)))

mock:                #<procedure:mock>

which-call:          0

actual-call-args:    (arguments 1)

expected-call-args:  (arguments foo)

Mock called with unexpected arguments

--------------------

> (check-mock-calls
   void-mock (list (arguments 1) (arguments 'foo) (arguments #:bar "baz")))

--------------------

FAILURE

name:                check-mock-calls

location:            eval:7:0

params:

  '(#<procedure:mock> ((arguments 1) (arguments foo) (arguments #:bar "baz")))

mock:                #<procedure:mock>

actual-num-calls:    2

expected-num-calls:  3

missing-calls:       ((arguments #:bar "baz"))

Mock called less times than expected

--------------------

procedure

(check-mock-called-with? m args)  void?

  m : mock?
  args : arguments
A rackunit check that passes if m has been called with args.

Examples:
> (define void-mock (mock #:behavior void))
> (check-mock-called-with? void-mock (arguments 'foo))

--------------------

FAILURE

name:           check-mock-called-with?

location:       eval:2:0

params:         '(#<procedure:mock> (arguments foo))

expected-args:  (arguments foo)

actual-calls:   ()

No calls were made matching the expected arguments

--------------------

> (void-mock 'foo)
> (check-mock-called-with? void-mock (arguments 'foo))

procedure

(check-mock-num-calls m n)  void?

  m : mock?
  n : exact-positive-integer?
A rackunit check that passes if m has been called exactly n times.

Examples:
> (define void-mock (mock #:behavior void))
> (check-mock-num-calls void-mock 1)

--------------------

FAILURE

name:       check-mock-num-calls

location:   eval:2:0

params:     '(#<procedure:mock> 1)

--------------------

> (void-mock 'foo)
> (check-mock-num-calls void-mock 1)

procedure

(check-call-history-names h names)  void?

  h : call-history?
  names : (listof symbol?)
A rackunit check that passes if h contains a history of calls by mocks with names.

Examples:
> (define h (call-history))
> (define m1 (mock #:name 'm1 #:behavior void #:external-histories (list h)))
> (define m2 (mock #:name 'm2 #:behavior void #:external-histories (list h)))
> (m1 'foo)
> (m2 'bar)
> (check-call-history-names h (list 'm1 'm2))
> (m1 'baz)
> (check-call-history-names h (list 'm1 'm2))

--------------------

FAILURE

name:                check-call-history-names

location:            eval:8:0

params:

  (list

 (call-history

  (box

   (list

    (mock-call 'm1 (arguments 'foo) '(#<void>))

    (mock-call 'm2 (arguments 'bar) '(#<void>))

    (mock-call 'm1 (arguments 'baz) '(#<void>)))))

 '(m1 m2))

history:

  #(struct:call-history #&(#(struct:mock-call m1 (arguments foo) (#<void>)) #(struct:mock-call m2 (arguments bar) (#<void>)) #(struct:mock-call m1 (arguments baz) (#<void>))))

actual-num-calls:    3

expected-num-calls:  2

extra-call-names:    (m1)

Mock call history contained more calls than expected

--------------------

Added in version 1.2 of package mock-rackunit.