Skip to content

Instantly share code, notes, and snippets.

@antony
Last active November 21, 2015 11:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antony/63f0eebea940c31a6a1f to your computer and use it in GitHub Desktop.
Save antony/63f0eebea940c31a6a1f to your computer and use it in GitHub Desktop.
Writing spock language in javascript with sweet.js (WIP)
let spec = macro {
rule { $name:lit { $body ... } } => {
describe($name, function () {
$body ...
});
}
}
let def = macro {
rule { $name:lit { $body ... } } => {
it($name, function(done) {
$body ...
});
}
}
let given = macro {
rule { : $($body) ... } => {
$body ...
}
}
let when = macro {
rule { : $body ... } => {
$body ...
}
}
let beforeEach = macro {
rule { ( $done:ident ) { $body ... } } => {
beforeEach(function ($done) {
$body ...
});
}
}
let afterEach = macro {
rule { ( $done:ident ) { $body ... } } => {
afterEach(function ($done) {
$body ...
});
}
}
let then = macro {
rule { : $($assertion ... ;) } => {
$(expect($assertion ...)).to.equal(true);
}
}
export describe;
export it;
export beforeEach;
export afterEach;
spec 'As a user I would like to add numbers' {
def 'my test' {
given:
var a = 1,
b = 2;
when:
var c = a + b;
then:
c == 3;
a == 1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment