Sha256: 170577e0b0d716f3e120959e94c9109aea9fb7dc19fa369ad00a81d0ad83b757

Contents?: true

Size: 1.59 KB

Versions: 20

Compression:

Stored size: 1.59 KB

Contents

describe "Joosy.Module", ->

  it "tracks inheritance", ->
    class A
    class B extends A
    class C extends B
    class D

    for a in [A, B, C, D]
      for b in [A, B, C, D]
        if (a == b) ||
          ((a == B) && (b == A)) ||
          ((a == C) && (b != D))
            expect(Joosy.Module.hasAncestor a, b).toBeTruthy()
        else
          expect(Joosy.Module.hasAncestor a, b).toBeFalsy()

  # We need this check to ensure we are not overpolluting the namespace
  it "has minimal set of properties", ->
    class Klass extends Joosy.Module

    expect(Object.extended(Klass).keys()).toEqual ['__namespace__', '__className', 'hasAncestor', 'aliasMethodChain', 'aliasStaticMethodChain', 'merge', 'include', 'extend', '__super__']
    expect(Object.extended(Klass.prototype).keys()).toEqual ['constructor']

  it "includes", ->
    Module =
      property: 'value'

    class Klass extends Joosy.Module
      @include Module

    expect(Klass::property).toEqual 'value'
    expect(Klass.property).toBeUndefined()

  it "extends", ->
    TestModule =
      property: 'value'

    class Klass extends Joosy.Module
      @extend TestModule

    expect(Klass.property).toEqual 'value'
    expect(Klass::property).toBeUndefined()

  it "runs callbacks", ->
    TestModule =
      property: 'value'
      included: sinon.spy()
      extended: sinon.spy()

    class Klass extends Joosy.Module
      @include TestModule
      @extend TestModule

    for callback in ['included', 'extended']
      expect(TestModule[callback].callCount).toEqual 1
      expect(TestModule[callback].getCall(0).calledOn(Klass)).toBeTruthy()

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
joosy-1.2.0.alpha.73 spec/joosy/core/modules/module_spec.coffee
joosy-1.2.0.alpha.71 spec/joosy/core/modules/module_spec.coffee
joosy-1.2.0.alpha.70 spec/joosy/core/modules/module_spec.coffee
joosy-1.2.0.alpha.68 spec/joosy/core/modules/module_spec.coffee
joosy-1.2.0.alpha.67 spec/joosy/core/modules/module_spec.coffee
joosy-1.2.0.alpha.66 spec/joosy/core/modules/module_spec.coffee
joosy-1.2.0.alpha.65 spec/joosy/core/modules/module_spec.coffee
joosy-1.2.0.alpha.64 spec/joosy/core/modules/module_spec.coffee
joosy-1.2.0.alpha.63 spec/joosy/core/modules/module_spec.coffee
joosy-1.2.0.alpha.62 spec/joosy/core/modules/module_spec.coffee
joosy-1.2.0.alpha.59 spec/joosy/core/modules/module_spec.coffee
joosy-1.2.0.alpha.58 spec/joosy/core/modules/module_spec.coffee
joosy-1.2.0.alpha.57 spec/joosy/core/modules/module_spec.coffee
joosy-1.2.0.alpha.56 spec/joosy/core/modules/module_spec.coffee
joosy-1.2.0.alpha.55 spec/joosy/core/modules/module_spec.coffee
joosy-1.2.0.alpha.54 spec/joosy/core/modules/module_spec.coffee
joosy-1.2.0.alpha.53 spec/joosy/core/modules/module_spec.coffee
joosy-1.2.0.alpha.52 spec/joosy/core/modules/module_spec.coffee
joosy-1.2.0.alpha.51 spec/joosy/core/modules/module_spec.coffee
joosy-1.2.0.alpha.41 spec/joosy/core/modules/module_spec.coffee