Skip to content

Instantly share code, notes, and snippets.

@searls
Created July 19, 2012 18:00
Show Gist options
  • Save searls/3145686 to your computer and use it in GitHub Desktop.
Save searls/3145686 to your computer and use it in GitHub Desktop.
window.CountCalculator=window.PriceCalculator=window.TaxCalculator=window.ShippingCaclulator = {}
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", ->
Given -> window.ChainsCalls = chain: jasmine.createSpy()
Given -> @dependencies = [CountCalculator, PriceCalculator, TaxCalculator, ShippingCaclulator]
Given -> ChainsCalls.chain.when(@dependencies, "calculate").thenReturn("yay")
When -> @result = Invoice.build()
Then -> expect(@result).toEqual("yay")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment