Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
55 lines (41 sloc) 1.3 KB
_ = require('underscore')
invoke = (method_name, args...) ->
if _.isFunction(@actual[method_name])
@actual[method_name].apply(@actual, args)
else
args.unshift(@actual)
_[method_name].apply(@actual, args)
beforeEach ->
@addMatchers
toBeEmpty: ->
invoke.call(this, 'isEmpty')
toInclude: (items...) ->
_(items).all (item) =>
invoke.call(this, 'include', item)
toIncludeAny: (items...) ->
_(items).any (item) =>
invoke.call(this, 'include', item)
toBeCompact: ->
elements = invoke.call(this, 'map', _.identity)
_.isEqual elements, _.compact(elements)
toBeUnique: ->
elements = invoke.call(this, 'map', _.identity)
_.isEqual elements, _.uniq(elements)
toRespondTo: (methods...)->
_.all methods, (method) =>
_.isFunction(@actual[method])
toRespondToAny: (methods...)->
_.any methods, (method) =>
_.isFunction(@actual[method])
toHave: (attrs...) ->
_.all attrs, (attr) =>
invoke.call(this, 'has', attr)
toHaveAny: (attrs...) ->
_.any attrs, (attr) =>
invoke.call(this, 'has', attr)
toBeAnInstanceOf: (clazz) ->
@actual instanceof clazz
toBeA: (clazz) ->
@actual instanceof clazz
toBeAn: (clazz) ->
@actual instanceof clazz