clecs.test.mock

Mock worlds that delegate their operations to functions.

Because protocol method can’t be mocked using with-redefs etc. systems and world backends are difficult to unit test. Paying one level of indirection, protocols can be mocked using functions defined in this module.

Examples:

(def foo-system [w dt]
  (doseq [eid (world/query w (all :FooComponent
                                  (any :BarComponent
                                       :BazComponent)))]
    (world/remove-component w eid :FooComponent)))

(fact "foo-system does stuff."
      (let [w (mock/mock-editable-world)
            q (all :FooComponent
                   (any :BarComponent
                        :BazComponent))]
        (foo-system w anything) => anything
        (provided (mock/query w q) => [..e1.. ..e2..]
                  (mock/remove-component w ..e1.. :FooComponent) => nil
                  (mock/remove-component w ..e2.. :FooComponent) => nil)))

-component

(-component & _)

-run

(-run & _)

-set-component

(-set-component & _)

-world

(-world & _)

add-entity

(add-entity & _)

component

(component & _)

mock-editable-world

(mock-editable-world)

mock-world

(mock-world)

mock-world-factory

process!

(process! & _)

query

(query & _)

remove-component

(remove-component & _)

remove-entity

(remove-entity & _)