jasmine-set brings rspec's let
syntax to the Jasmine behavior-driven development framework for testing JavaScript code. The set
global function is provided, which allows the spec writer to define lazy global accessors that can be refined in nested specs. To achieve this behavior, the Suite.prototype.finish
function from Jasmine is wrapped.
In Ecmascript, let
is a reserved word that allows for block-level scoping (as opposed to var
, which is functionally-scoped).
describe 'House', ->
set 'opts', -> {}
set 'house', -> new House(opts)
it 'has a door', -> expect(house).toHaveADoor()
describe 'with no doors', ->
set 'opts', -> { doors: 0 }
it 'does not have a door', -> expect(house).not.toHaveADoor()
- underscore (~1.6)
- node >= 0.8
$ npm i
$ ./jake build
$ ./jake spec [DEBUG=1] [SPEC=./spec/set.coffee]
Rapid7 2014