Switch branches/tags
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
60 lines (44 sloc) 1.45 KB



should      = require 'should'
nailCore    = require 'nail-core'
fields      = require('../coverage/instrument/lib/module.js').fields
_           = require 'underscore'
they        = it #more natural language for describing array properties


describe 'fields', ->
  it 'is an Object', ->
    (_.isObject fields)

The "aspect" defines which section of the class definition the module handles.

  it 'has a "aspect" string"', -> 'string'

  it 'its aspect is "fields"', ->
    fields.aspect.should.equal 'fields'

This aspect is optional.

  it 'does not crash if the class has no fields', ->
    Person = ->
    Person.definition = {}
    fields.augment Person

The augment function exists...

  it 'has a "augment" function', ->
    (_.isFunction fields.augment)

...and adds fields to the prototype.

  it 'adds a field to a class prototype', ->
    Person = ->
    Person.definition =
        name: 'anon'

    fields.augment Person
    x = new Person 'anon'

The module can be used as a nail module.

  it 'can be used as a nail module', ->
    nail = nailCore.use fields
    lib = Person:
        name: 'anon'

    x = new lib.Person 'anon'