 
 describe "Model.apply", ->
   it "Applies given sync stream of functions to the Model", ->
-    b = lib.Model(1)
+    b = Model(1)
     values = collect(b)
     b.apply(Bacon.fromArray([twice, twice, twice]))
     expect(values).to.deep.equal([1, 2, 4, 8])
   it "Applies given async stream of functions to the Model", (done) ->
-    b = lib.Model(1)
+    b = Model(1)
     b.onValue (val) ->
       if val == 2 then done()
     b.apply Bacon.fromBinder (sink) ->

expect = require("chai").expect
Bacon = require "baconjs"
lib = require "../src/bacon.model"
twice = (x) -> x * 2

grep = process.env.grep


describe "Model.set", ->
  it "sets new value", ->
    b = Model()
    values = collect(b)
    b.set("wat")
    b.set("asdf")
    expect(values).to.deep.equal(["wat", "asdf"])
  it "handles undefined like any other value", ->
    b = Model()
    values = collect(b)
    b.set("wat")
    b.set(undefined)
    expect(values).to.deep.equal(["wat", undefined])
  it "skips duplicate values", ->
    b = Model()
    values = collect(b)
    b.set("wat")
    b.set("wat")
    expect(values).to.deep.equal(["wat"])
  it "works when setting value in during bacon dispatch", ->
    b = Model("init")
    Bacon.once(1).onValue ->
      b.set("value1")
    expect(b.get()).to.equal("value1")
  it "does not call value if it is a function", ->
    b = Model()
    f = -> 3
    b.set(f)
    expect(b.get()).to.equal(f)

describe "Model.get", ->
  it "returns current value", ->
    b = Model("hello")
    expect(b.get()).to.equal("hello")
    b.set("hallo")
    expect(b.get()).to.equal("hallo")
  it "defaults to undefined", ->
    b = Model()
    expect(b.get()).to.equal(undefined)

describe "Model initial value", ->
  it "is sent", ->
    cylinders = Model(12)
    expect(collect(cylinders)).to.deep.equal([12])
  it "handles undefined like any other value", ->
    cylinders = Model(undefined)
    expect(collect(cylinders)).to.deep.equal([undefined])
  it "can be omitted", ->
    cylinders = Model()
    expect(collect(cylinders)).to.deep.equal([])

describe "Model.modify", ->
  it "modifies current value with given function", ->
    b = Model(1)
    values = collect(b)
    b.modify(twice)
    b.modify(twice)
