This repository was archived by the owner on Dec 27, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathHelpers.coffee
More file actions
executable file
·66 lines (49 loc) · 1.9 KB
/
Copy pathHelpers.coffee
File metadata and controls
executable file
·66 lines (49 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
class SinonObjects
forbiddenNames: ['create', 'get', 'restore', 'restoreAll']
get: (name)->
return @[name]
restore:(name)->
if not @[name]
console.warn "Trying to restore a non-existing spy/stub with name: #{name}"
return
if @[name].restore
@[name].restore()
delete @[name]
return
restoreAll: ->
for key of @
@restore key
class SinonSpies extends SinonObjects
create: (name, obj, method)->
expect(name).to.be.a("string")
if @forbiddenNames.indexOf(name) >= 0
throw Error("A spy can't be named '#{name}'. Please choose another name.")
if not obj and not method
# Creates an anonymous function that records arguments, this value, exceptions and return values for all calls.
return @[name] = sinon.spy()
if not method
expect(obj).to.be.a("function")
return @[name] = sinon.spy(obj)
expect(method).to.be.a "string"
if @[name]
@restore name
return @[name] = sinon.spy(obj, method)
class SinonStubs extends SinonObjects
create: (name, obj, method, func)->
expect(name).to.be.a("string")
if @forbiddenNames.indexOf(name) >= 0
throw Error("A stub can't be named '#{name}'. Please choose another name.")
if not obj and not method
return @[name] = sinon.stub()
expect(method).to.be.a("string")
if @[name]
@restore name
return @[name] = sinon.stub(obj, method, func)
# A test spy is a function that records arguments, return value,
# the value of this and exception thrown (if any) for all its calls.
# A test spy can be an anonymous function or it can wrap an existing function or object method.
# To learn more http://sinonjs.org/docs/#spies-api
spies = this.spies = new SinonSpies()
# Test stubs are functions (spies) with pre-programmed behavior.
# This is a wrapper for sinonjs stubs to learn more http://sinonjs.org/docs/#stubs-api
stubs = this.stubs = new SinonStubs()