pulsar/spec/stdlib/underscore-extensions-spec.coffee
Nathan Sobo acc0503684 Merge remote-tracking branch 'origin/master' into config
Conflicts:
	src/app/keymap.coffee
	src/extensions/outline-view/src/keymap.coffee
	src/extensions/outline-view/src/tag-reader.coffee
	src/packages/fuzzy-finder/spec/fuzzy-finder-spec.coffee
	src/packages/fuzzy-finder/src/fuzzy-finder.coffee
2012-12-18 20:32:05 -07:00

33 lines
1.2 KiB
CoffeeScript

_ = require 'underscore'
describe "underscore extensions", ->
describe "_.adviseBefore", ->
[object, calls] = []
beforeEach ->
calls = []
object = {
method: (args...) ->
calls.push(["original", this, args])
}
it "calls the given function before the advised method", ->
_.adviseBefore object, 'method', (args...) -> calls.push(["advice", this, args])
object.method(1, 2, 3)
expect(calls).toEqual [['advice', object, [1, 2, 3]], ['original', object, [1, 2, 3]]]
it "cancels the original method's invocation if the advice returns true", ->
_.adviseBefore object, 'method', -> false
object.method(1, 2, 3)
expect(calls).toEqual []
describe "_.endsWith", ->
it "returns whether the given string ends with the given suffix", ->
expect(_.endsWith("test.txt", ".txt")).toBeTruthy()
expect(_.endsWith("test.txt", "txt")).toBeTruthy()
expect(_.endsWith("test.txt", "test.txt")).toBeTruthy()
expect(_.endsWith("test.txt", "")).toBeTruthy()
expect(_.endsWith("test.txt", ".txt2")).toBeFalsy()
expect(_.endsWith("test.txt", ".tx")).toBeFalsy()
expect(_.endsWith("test.txt", "test")).toBeFalsy()