Skip to content

Instantly share code, notes, and snippets.

@kbaribeau
Forked from searls/invoice.coffee
Created July 19, 2012 18:06
Show Gist options
  • Save kbaribeau/3145718 to your computer and use it in GitHub Desktop.
Save kbaribeau/3145718 to your computer and use it in GitHub Desktop.
window.CountCalculator=window.PriceCalculator=window.TaxCalculator=window.ShippingCaclulator = {
calculate: (num) -> (num == undefined ? 0 : num + 1) }
ChainsCalls =
chain: (dependencies, method) ->
_(dependencies).inject((memo, dependency) ->
dependency[method](memo)
, undefined)
Invoice =
build: ->
ChainsCalls.chain([CountCalculator, PriceCalculator, TaxCalculator, ShippingCaclulator], "calculate")
describe "ChainsCalls", ->
Given -> @a = go: jasmine.createSpy().andReturn("foo")
Given -> @b = go: jasmine.createSpy().when("foo").thenReturn("bar")
When -> @result = ChainsCalls.chain([@a,@b], "go")
Then -> expect(@result).toBe("bar")
describe "Invoice", ->
When -> @result = Invoice.build()
Then -> expect(@result).toEqual(4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment