mirror of
https://github.com/leafo/moonscript.git
synced 2024-12-08 01:54:24 +00:00
start a spec writing guide
This commit is contained in:
parent
6082a86b11
commit
c451418282
@ -24,6 +24,8 @@ To run tests, execute from the root directory:
|
|||||||
busted
|
busted
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Writing specs is a bit more complicated. Check out [the spec writing guide](spec/README.md).
|
||||||
|
|
||||||
## License (MIT)
|
## License (MIT)
|
||||||
|
|
||||||
Copyright (C) 2015 by Leaf Corcoran
|
Copyright (C) 2015 by Leaf Corcoran
|
||||||
|
58
spec/README.md
Normal file
58
spec/README.md
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
|
||||||
|
# MoonScript Spec guide
|
||||||
|
|
||||||
|
Because MoonScript is written in MoonScript, and MoonScript specs are written
|
||||||
|
in MoonScript, you need to be aware of which copy of MoonScript is actually
|
||||||
|
executing the specs.
|
||||||
|
|
||||||
|
A system installed version of MoonScript is recommended to run the specs (and
|
||||||
|
for development). This means that you'll typically have two versions of
|
||||||
|
MoonScript available in the load path:
|
||||||
|
|
||||||
|
* The system version
|
||||||
|
* The version in the current directory
|
||||||
|
|
||||||
|
> A system install is recommended because you'll always want a functioning
|
||||||
|
> version of MoonScript to compile with in case you break your development
|
||||||
|
> version.
|
||||||
|
|
||||||
|
When developing you want to make ensure the tests are executing your changes in
|
||||||
|
the current directory, and not testing the system install.
|
||||||
|
|
||||||
|
Code running in Busted will have the system install take precedence over the
|
||||||
|
loaded version. That means that if you `require "moonscript.base"` for a test,
|
||||||
|
you won't get the local copy.
|
||||||
|
|
||||||
|
The `with_dev` spec helper will ensure that any require calls within the spec
|
||||||
|
that ask for MoonScript modules. `with_dev` calls a setup and teardown that
|
||||||
|
replaces `_G.require` with a custom version.
|
||||||
|
|
||||||
|
You'll use it like this:
|
||||||
|
|
||||||
|
```moonscript
|
||||||
|
import with_dev from require "spec.helpers"
|
||||||
|
describe "moonscript.base", ->
|
||||||
|
local moonscript
|
||||||
|
|
||||||
|
with_dev!
|
||||||
|
|
||||||
|
it "should load code", ->
|
||||||
|
-- the local version is loaded
|
||||||
|
moonscript = require "moonscript"
|
||||||
|
moonscript.load "print 12"
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
`with_dev`'s require function will load the `.lua` files in the local
|
||||||
|
directory, not the `moon` ones. You're responsible for compiling them first
|
||||||
|
before running the tests.
|
||||||
|
|
||||||
|
You might do
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ make compile_system; busted
|
||||||
|
```
|
||||||
|
|
||||||
|
> `make compile_system` is a makefile task included in the repo that will build
|
||||||
|
> MoonScript in the current directory with the version installed to the system
|
||||||
|
|
Loading…
Reference in New Issue
Block a user