UNPKG

7.03 kBtext/coffeescriptView Raw
1ipso = require '../lib/ipso'
2should = require 'should'
3{deferred, util} = require 'also'
4Loader = require '../lib/loader'
5does = require 'does'
6
7
8
9describe 'ipso', ->
10
11 before ->
12
13 resolver = => @resolve
14
15 @fakeit = (title, fn) =>
16 @test = timer: _onTimeout: ->
17 fn.call @, resolver()
18
19
20 @resolvingPromise = deferred (action) ->
21 action.resolve 'RESULT'
22
23 beforeEach -> @RESULT = undefined
24
25
26 it 'works normally', ->
27
28 #console.log 'in works normally'.bold
29 true.should.equal true
30
31 # it 'still works normally', ipso ->
32
33 # console.log 'in still works normally'.bold
34 # true.should.equal false
35
36
37 context 'it warns on injecting done into context', ipso (done) ->
38
39
40 context 'for mocha tests', ->
41
42
43 it 'goes in front of a test function like this:', ipso ->
44
45 # console.log @resolvingPromise
46
47
48 context 'injection for synchronous tests', ->
49
50 it 'returns a function with done as the only argument if no "done"', (done) ->
51
52 #
53 # injection is asynchronous even when mocha test is not
54 #
55
56 fn = ipso (zlib, net) ->
57 args = util.argsOf fn
58 args.should.eql ['done']
59 done()
60
61 context 'injection for asynchronous tests', ->
62
63 it 'returns a function with done as the only argument if "done"', (done) ->
64
65 fn = ipso (done, zlib, net) ->
66 args = util.argsOf fn
67 args.should.eql ['done']
68 done()
69
70
71 context 'it can inject into before', ->
72
73 before ipso (http) -> @http = http
74
75 it 'did inject http', ipso (done) ->
76
77 @http = require 'http'
78 done()
79
80
81 it 'calls each test "runtime" into does as test starts up', ipso (done) ->
82
83 spec = does._test().runtime.current.spec
84
85 spec.title.should.equal 'calls each test "runtime" into does as test starts up'
86 done()
87
88
89 it 'still fails as it should', ->
90
91 @resolve = (error) ->
92 #console.log error
93 error.name.should.equal 'AssertionError'
94 done()
95
96 @fakeit 'fails this', ipso (done) ->
97 true.should.equal 'this is expected to fail'
98
99
100
101 it 'preserves the mocha context', ipso (done) ->
102
103 should.exist @resolvingPromise
104 done()
105
106
107 it 'initializes loader with starting cwd', ipso (done) ->
108
109 Loader._test().dir.should.equal process.cwd()
110 done()
111
112
113 it 'passes from within the promise resolution / fullfillment handler', ipso (done) ->
114
115 @resolvingPromise().then (result) ->
116
117 result.should.equal 'RESULT'
118 done()
119
120
121 it 'fails from within the promise resolution / fullfillment handler', ->
122
123 @resolve = (error) ->
124 error.name.should.equal 'AssertionError'
125 done()
126
127 @fakeit 'fails this', ipso (done) =>
128
129
130 it 'injects mode nodules', ipso (done, should) ->
131
132 should.should.equal require 'should'
133 done()
134
135
136 describe 'it can inject into describe', ipso (vm) ->
137
138 context 'it can inject into context', ipso (net) ->
139
140 it 'confirms', ->
141
142 vm.should.equal require 'vm'
143 net.should.equal require 'net'
144
145
146 it 'can inject into synchronous test', ipso (zlib, net) ->
147
148 net.should.equal require 'net'
149 zlib.should.equal require 'zlib'
150
151
152 it 'fails when injecting undefined node module', (done) ->
153
154 @resolve = (error) ->
155 error.should.match /Cannot find module/
156 done()
157
158 @fakeit 'fails this', ipso (facto, i) ->
159
160
161 it 'succeeds when injecting undefined LocalModule', ipso (LocalModule) ->
162
163 LocalModule.$ipso.PENDING.should.equal true
164
165
166
167 it 'injects modules as spectatable', ipso (facto, should) ->
168
169 should.does.should.be.an.instanceof Function
170 facto()
171
172
173 it 'defines tag() for hook prepping spectatable objects the do not reset stubs at injection', (done) ->
174
175 ipso.tag.should.be.an.instanceof Function
176 done()
177
178 context 'tag()', ->
179
180 it 'registers spectated object as tagged', (done) ->
181
182 object = this: 1
183
184 ipso.tag( tagName: object ).then ->
185
186 expx = does._test().entities
187 lastone = expx[uuid] for uuid of expx
188 lastone.name.should.equal 'tagName'
189 lastone.tagged.should.equal true
190 object.does.should.be.an.instanceof Function
191 lastone.object.should.equal object
192 done()
193
194
195 it 'can tag more than one at a time', ipso (facto) ->
196
197 ipso.tag
198
199 satelite: class Satelite
200 planet: class Planet
201 star: class Star
202 π: class π
203
204 .then ->
205
206 tagged = does._test().tagged
207
208 should.exist tagged['satelite']
209 should.exist tagged['planet']
210 should.exist tagged['star']
211 should.exist tagged['π']
212 facto()
213
214 context 'mock', ->
215
216 it 'returns a mock object', ->
217
218 mock = ipso.mock 'thing'
219 mock.is.should.be.an.instanceof Function
220 mock.does.should.be.an.instanceof Function
221
222 it 'can assert as self', ->
223
224 mock1 = ipso.mock 'something'
225 mock2 = ipso.mock 'something else'
226
227 try mock1.is mock2
228 catch error
229 error.should.be.an.instanceof require('assert').AssertionError
230 error.should.match /expected/
231
232 try mock1.is 'something else'
233 catch error
234 error.actual.should.equal 'something'
235 error.expected.should.equal 'something else'
236
237
238 # it 'throws expected functions not called instead of timeout even if timeout is reset', ipso (facto, Something) ->
239
240 # @timeout 10
241 # Something.does
242 # something: -> 'okgood'
243 # somethingElse: -> facto()
244
245 # Something.something()
246 # # Something.somethingElse()
247
248 # # 1 | {
249 # # 2 | "Something": {
250 # # 3 | "functions": {
251 # # 4 | "Object.something()": "was called",
252 # # 5 | "Object.somethingElse()": "was NOT called"
253 # # 6 | }
254 # # 7 | }
255 # # 8 | }
256
257 # #
258 # # not bothering to try and make a 'passing test' capable
259 # # of testing that this test fails by timeout
260 # #
261
262
263
264