Giter Site home page Giter Site logo

wedge's Introduction

wedge

Function call verification for use with clojure.test

Installation

Add the following dependency to your project.clj file:

Clojars Project

Usage

(ns my-tests
  (:require [clojure.test :refer :all]
            [wedge.core :refer :all]))

(defn assert-some-param [param]
  (assert (integer? param) "param needs to be an integer"))

(defn helper-fn [amount param]
  (+ amount param))

(defn main-fn [param]
  (assert-some-param param)
  (if (odd? (helper-fn 1 param))
    (* param param)
    (dec param)))

(deftest main-fn-tests
  (with-wedge [assert-some-param assert-counter
               helper-fn helper-counter]
    (is (= 9 (main-fn 2)))
    
    ;; was assert-some-param called at all?
    (is (called? assert-counter))
    
    (is (= 1 (main-fn 1)))
    
    ;; count the total number of times helper-fn was called
    (is (= 2 (total-calls helper-counter)))
    
    ;; count the total number of times helper-fn was call with '1' for both arguments
    (is (= 1 (call-count helper-counter [1 1])))
    
    ;; count the total number of times helper-fn was call with '1' for the first argument
    (is (= 2 (call-count helper-counter [1 ?])))
    
    ;; count the total number of times helper-fn was call with '1' for the first argument
    ;;  and any second argument greater than 0
    (is (= 2 (call-count helper-counter [1 [? #(< 0 %)]])))))

Documentation

API

Rationale

Often times our code is composed of fns for which there are already tests. Assertions, validations, helper functions, etc. When writing a test for a top level fn, or a fn composed of other fns for which their are already tests, we don't want to attempt to test the logic in the helper fns, we simply want to verify that the helper fn is called. The helper fn test is responsible for verifying the helper fn, not the test we are currently writing.

To this end, wedge. Hopefuly most of the time called? is sufficient for a majority of needs, but there is some flexibility added in case you need to test a range of parameters, such as Moq, or some similar library.

License

Copyright © 2015 Chris LaVoie

Distributed under the Eclipse Public License, the same as Clojure.

wedge's People

Contributors

clavoie avatar clavoie-dk avatar

Stargazers

Bruce Lindsay avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.