Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 28 additions & 6 deletions .github/workflows/clojure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,39 @@ name: Clojure CI
on:
push:
branches: [ master ]
tags: [ '[0-9]*' ]
Comment thread
alexanderjamesking marked this conversation as resolved.
Resolved
pull_request:
branches: [ master ]

jobs:
build:
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: DeLaGuardo/setup-clojure@13
with:
cli: latest
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '21'
- name: Cache dependencies
uses: actions/cache@v4
with:
path: |
~/.m2/repository
~/.gitlibs
.cpcache
key: ${{ runner.os }}-deps-${{ hashFiles('deps.edn') }}
restore-keys: ${{ runner.os }}-deps-
- name: Install dependencies
run: lein deps
run: clojure -P -M:test
- name: Run tests
run: lein test
- name: Coverage
run: lein coverage
run: clojure -M:test -m cognitect.test-runner
- name: Deploy to Clojars
if: startsWith(github.ref, 'refs/tags/')
env:
CLOJARS_USERNAME: ${{ secrets.CLOJARS_USERNAME }}
CLOJARS_PASSWORD: ${{ secrets.CLOJARS_PASSWORD }}
RELEASE_VERSION: ${{ github.ref_name }}
run: clojure -T:build deploy-jar
6 changes: 3 additions & 3 deletions .github/workflows/clojurescript.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ on:

jobs:
build:
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '21'
- uses: actions/setup-node@v4
with:
node-version: '18'
node-version: '22'
- run: npm install
- run: npm test
12 changes: 2 additions & 10 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
/target
/classes
/checkouts
pom.xml
pom.xml.asc
*.jar
*.class
/.lein-*
pom.xml
/.nrepl-port
.hgignore
.hg/
resources/public/cljs
/out
figwheel_server.log
/.cljs_rhino_repl
.cpcache
.shadow-cljs
node_modules
14 changes: 14 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Contributing

Pull requests are welcome. Please run the test suite and check that all tests pass prior to submission.

```
make test # Clojure tests
make test-cljs # ClojureScript tests (requires npm install)
```

## Releasing

1. Commit and push any final changes to master
2. Tag the release: `git tag <version> && git push --tags` — CI deploys to Clojars
3. Verify the release appears on https://clojars.org/tortue/spy
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.PHONY: test test-cljs clean jar deploy

test:
clojure -M:test -m cognitect.test-runner

test-cljs:
npm test

clean:
clojure -T:build clean

jar:
clojure -T:build jar

deploy:
clojure -T:build deploy-jar
30 changes: 16 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,23 @@

Spy - a Clojure and ClojureScript library for stubs, spies and mocks. This library is aimed at users of [clojure.test](https://clojure.github.io/clojure/clojure.test-api.html).

It records calls and responses to and from a function, allowing you to verify interactions. Terms used in this library are as follows, there are many different names for Mocks, see [Test Doubles, Fakes, Mocks and Stubs](https://blog.pragmatists.com/test-doubles-fakes-mocks-and-stubs-1a7491dfa3da) for more detail.
It records calls and responses to and from a function, allowing you to verify interactions.

1. Stub - function that returns a hardcoded value
2. Spy - wrapper around a function allowing verification of interactions with the function
3. Mock - function with a fake implementation to be used in place of the real thing
3. Mock - function with a fake implementation to be used in place of the real thing

## Installation

**deps.edn**
```clojure
{:deps {tortue/spy {:mvn/version "2.15.0"}}}
```

**Leiningen (project.clj)**
```clojure
[tortue/spy "2.15.0"]
```

## Usage

Expand Down Expand Up @@ -262,23 +274,13 @@ can also be used to spy on multiple protocols: `(spy.protocol/spy Proto1...Proto

## Contributing

Pull requests are welcome. Please run the test suite and check that all tests pass prior to submission.

Tests:
```
$ lein test
```

Code coverage:
```
$ lein cloverage
```
Pull requests are welcome. See [CONTRIBUTING.md](CONTRIBUTING.md) for details.

## License
```
MIT License

Copyright (c) 2025 Alexander James King
Copyright (c) 2026 Alexander James King

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion bin/setup
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ set -euxo pipefail

cd "$(dirname "${BASH_SOURCE[0]}")/.."

lein deps
clj -P -M:test
npm install
2 changes: 1 addition & 1 deletion bin/test
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ set -euxo pipefail

cd "$(dirname "${BASH_SOURCE[0]}")/.."

lein test
clj -M:test -m cognitect.test-runner
npm test
42 changes: 42 additions & 0 deletions build.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
(ns build
(:require [clojure.tools.build.api :as b]
[deps-deploy.deps-deploy :as deploy]))

(def lib 'tortue/spy)
(def version (or (System/getenv "RELEASE_VERSION") "dev"))
(def class-dir "target/classes")
(def src-dirs ["src/clj" "src/cljc" "src/cljs" "resources"])
(def basis (delay (b/create-basis {:project "deps.edn"})))
(def jar-file (format "target/%s-%s.jar" (name lib) version))
Comment thread
alexanderjamesking marked this conversation as resolved.
Resolved

(defn- assert-release-version []
(assert (re-matches #"\d+\.\d+\.\d+" version)
(str "RELEASE_VERSION must be set to a valid version (e.g. 2.16.0), got: " version)))

(defn clean [_]
(b/delete {:path "target"}))

(defn jar [_]
(b/delete {:path class-dir})
(b/write-pom {:class-dir class-dir
:lib lib
:version version
:basis @basis
:description "Spy - a Clojure and ClojureScript library for stubs, spies and mocks"
:url "https://github.com/alexanderjamesking/spy"
:scm {:url "https://github.com/alexanderjamesking/spy"}
:pom-data [[:licenses
[:license
[:name "MIT License"]
[:url "https://opensource.org/licenses/MIT"]]]]})
(b/copy-dir {:src-dirs src-dirs
:target-dir class-dir})
(b/jar {:class-dir class-dir
:jar-file jar-file}))
Comment thread
alexanderjamesking marked this conversation as resolved.
Resolved

(defn deploy-jar [_]
(assert-release-version)
(jar nil)
(deploy/deploy {:installer :remote
:artifact jar-file
:pom-file (b/pom-path {:lib lib :class-dir class-dir})}))
Comment thread
alexanderjamesking marked this conversation as resolved.
Resolved
11 changes: 11 additions & 0 deletions deps.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{:paths ["src/clj" "src/cljc" "src/cljs" "resources"]
:deps {}
:aliases
{:provided {:extra-deps {org.clojure/clojure {:mvn/version "1.12.1"}
org.clojure/clojurescript {:mvn/version "1.12.42"}}}
:test {:extra-paths ["test/clj" "test/cljc"]
:extra-deps {org.clojure/clojure {:mvn/version "1.12.1"}
io.github.cognitect-labs/test-runner {:git/tag "v0.5.1" :git/sha "dfb30dd"}}}
:build {:deps {io.github.clojure/tools.build {:mvn/version "0.10.5"}
slipset/deps-deploy {:mvn/version "0.2.2"}}
:ns-default build}}}
15 changes: 8 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"dependencies": {
"shadow-cljs": "3.1.7"
"shadow-cljs": "3.3.5"
},
"scripts": {
"test": "shadow-cljs compile test && node target/test.js"
Expand Down
14 changes: 0 additions & 14 deletions project.clj

This file was deleted.

11 changes: 11 additions & 0 deletions resources/clj-kondo.exports/tortue/spy/config.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{:lint-as {spy.assert/called? clojure.core/assert
Comment thread
alexanderjamesking marked this conversation as resolved.
Resolved
spy.assert/not-called? clojure.core/assert
spy.assert/called-once? clojure.core/assert
spy.assert/called-n-times? clojure.core/assert
spy.assert/called-with? clojure.core/assert
spy.assert/not-called-with? clojure.core/assert
spy.assert/called-once-with? clojure.core/assert
spy.assert/called-at-least-once? clojure.core/assert
spy.assert/called-at-least-n-times? clojure.core/assert
spy.assert/called-no-more-than-once? clojure.core/assert
spy.assert/called-no-more-than-n-times? clojure.core/assert}}
Loading