Last active
November 21, 2015 11:42
-
-
Save antony/63f0eebea940c31a6a1f to your computer and use it in GitHub Desktop.
Writing spock language in javascript with sweet.js (WIP)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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