Skip to content

Instantly share code, notes, and snippets.

@luciferous
Created September 19, 2011 21:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save luciferous/1227705 to your computer and use it in GitHub Desktop.
Save luciferous/1227705 to your computer and use it in GitHub Desktop.
Use JsMockito with NodeJS (patched for CommonJS Module 1.1 compliance)
#!/bin/sh
# Begin with an empty file.
echo > mockito.js
# Download and concatenate jshamcrest with jsmockito.
curl --silent --compressed \
http://jshamcrest.destaquenet.com/jshamcrest.js \
http://cloud.github.com/downloads/chrisleishman/jsmockito/jsmockito-1.0.4.js \
> mockito.js
# Patch a few things:
# - Compliance with CommonJS Module 1.1 specification
# - Throw Error objects instead of String objects
# - Declare JsMockito locally using `var`
patch mockito.js <<EOF
1646c1646
< JsMockito = {
---
> var JsMockito = {
2235c2235
< throw description.get();
---
> throw new Error(description.get());
2266c2266
< throw description.get();
---
> throw new Error(description.get());
2347a2348,2352
> exports.JsMockito = {};
> JsMockito.Integration.importTo(exports.JsMockito);
>
> exports.JsHamcrest = {};
> JsHamcrest.Integration.copyMembers(exports.JsHamcrest);
EOF
@Jimflip
Copy link

Jimflip commented Feb 19, 2012

thanks, this was useful.

@abovethewater
Copy link

echo the thanks - created fork for latest (v0.6.7) version of JsHamcrest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment