teaspoon-jasmine 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +7 -0
  2. data/lib/teaspoon-jasmine.rb +4 -0
  3. data/lib/teaspoon/jasmine/assets/jasmine/1.3.1.js +2602 -0
  4. data/lib/teaspoon/jasmine/assets/jasmine/2.0.3.js +2593 -0
  5. data/lib/teaspoon/jasmine/assets/jasmine/2.1.3.js +2908 -0
  6. data/lib/teaspoon/jasmine/assets/jasmine/2.2.0.js +3048 -0
  7. data/lib/teaspoon/jasmine/assets/jasmine/MIT.LICENSE +20 -0
  8. data/lib/teaspoon/jasmine/assets/support/jasmine-jquery-1.7.0.js +720 -0
  9. data/lib/teaspoon/jasmine/assets/support/jasmine-jquery-2.0.0.js +812 -0
  10. data/lib/teaspoon/jasmine/assets/support/jasmine-jquery-2.1.0.js +832 -0
  11. data/lib/teaspoon/jasmine/assets/teaspoon-jasmine1.js +1447 -0
  12. data/lib/teaspoon/jasmine/assets/teaspoon-jasmine2.js +1490 -0
  13. data/lib/teaspoon/jasmine/assets/teaspoon/jasmine1.coffee +10 -0
  14. data/lib/teaspoon/jasmine/assets/teaspoon/jasmine1/fixture.coffee +29 -0
  15. data/lib/teaspoon/jasmine/assets/teaspoon/jasmine1/initialize.coffee +1 -0
  16. data/lib/teaspoon/jasmine/assets/teaspoon/jasmine1/reporters/html.coffee +13 -0
  17. data/lib/teaspoon/jasmine/assets/teaspoon/jasmine1/responder.coffee +23 -0
  18. data/lib/teaspoon/jasmine/assets/teaspoon/jasmine1/runner.coffee +32 -0
  19. data/lib/teaspoon/jasmine/assets/teaspoon/jasmine1/spec.coffee +37 -0
  20. data/lib/teaspoon/jasmine/assets/teaspoon/jasmine1/suite.coffee +8 -0
  21. data/lib/teaspoon/jasmine/assets/teaspoon/jasmine2.coffee +10 -0
  22. data/lib/teaspoon/jasmine/assets/teaspoon/jasmine2/fixture.coffee +19 -0
  23. data/lib/teaspoon/jasmine/assets/teaspoon/jasmine2/initialize.coffee +23 -0
  24. data/lib/teaspoon/jasmine/assets/teaspoon/jasmine2/reporters/console.coffee +18 -0
  25. data/lib/teaspoon/jasmine/assets/teaspoon/jasmine2/reporters/html.coffee +11 -0
  26. data/lib/teaspoon/jasmine/assets/teaspoon/jasmine2/responder.coffee +39 -0
  27. data/lib/teaspoon/jasmine/assets/teaspoon/jasmine2/runner.coffee +26 -0
  28. data/lib/teaspoon/jasmine/assets/teaspoon/jasmine2/spec.coffee +36 -0
  29. data/lib/teaspoon/jasmine/assets/teaspoon/jasmine2/suite.coffee +8 -0
  30. data/lib/teaspoon/jasmine/framework.rb +35 -0
  31. data/lib/teaspoon/jasmine/templates/spec_helper.coffee +32 -0
  32. data/lib/teaspoon/jasmine/templates/spec_helper.js +32 -0
  33. data/lib/teaspoon/jasmine/version.rb +5 -0
  34. metadata +92 -0
@@ -0,0 +1,832 @@
1
+ /*!
2
+ Jasmine-jQuery: a set of jQuery helpers for Jasmine tests.
3
+
4
+ Version 2.0.7
5
+
6
+ https://github.com/velesin/jasmine-jquery
7
+
8
+ Copyright (c) 2010-2014 Wojciech Zawistowski, Travis Jeffery
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining
11
+ a copy of this software and associated documentation files (the
12
+ "Software"), to deal in the Software without restriction, including
13
+ without limitation the rights to use, copy, modify, merge, publish,
14
+ distribute, sublicense, and/or sell copies of the Software, and to
15
+ permit persons to whom the Software is furnished to do so, subject to
16
+ the following conditions:
17
+
18
+ The above copyright notice and this permission notice shall be
19
+ included in all copies or substantial portions of the Software.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28
+ */
29
+
30
+ +function (window, jasmine, $) { "use strict";
31
+
32
+ jasmine.spiedEventsKey = function (selector, eventName) {
33
+ return [$(selector).selector, eventName].toString()
34
+ }
35
+
36
+ jasmine.getFixtures = function () {
37
+ return jasmine.currentFixtures_ = jasmine.currentFixtures_ || new jasmine.Fixtures()
38
+ }
39
+
40
+ jasmine.getStyleFixtures = function () {
41
+ return jasmine.currentStyleFixtures_ = jasmine.currentStyleFixtures_ || new jasmine.StyleFixtures()
42
+ }
43
+
44
+ jasmine.Fixtures = function () {
45
+ this.containerId = 'jasmine-fixtures'
46
+ this.fixturesCache_ = {}
47
+ this.fixturesPath = 'spec/javascripts/fixtures'
48
+ }
49
+
50
+ jasmine.Fixtures.prototype.set = function (html) {
51
+ this.cleanUp()
52
+ return this.createContainer_(html)
53
+ }
54
+
55
+ jasmine.Fixtures.prototype.appendSet= function (html) {
56
+ this.addToContainer_(html)
57
+ }
58
+
59
+ jasmine.Fixtures.prototype.preload = function () {
60
+ this.read.apply(this, arguments)
61
+ }
62
+
63
+ jasmine.Fixtures.prototype.load = function () {
64
+ this.cleanUp()
65
+ this.createContainer_(this.read.apply(this, arguments))
66
+ }
67
+
68
+ jasmine.Fixtures.prototype.appendLoad = function () {
69
+ this.addToContainer_(this.read.apply(this, arguments))
70
+ }
71
+
72
+ jasmine.Fixtures.prototype.read = function () {
73
+ var htmlChunks = []
74
+ , fixtureUrls = arguments
75
+
76
+ for(var urlCount = fixtureUrls.length, urlIndex = 0; urlIndex < urlCount; urlIndex++) {
77
+ htmlChunks.push(this.getFixtureHtml_(fixtureUrls[urlIndex]))
78
+ }
79
+
80
+ return htmlChunks.join('')
81
+ }
82
+
83
+ jasmine.Fixtures.prototype.clearCache = function () {
84
+ this.fixturesCache_ = {}
85
+ }
86
+
87
+ jasmine.Fixtures.prototype.cleanUp = function () {
88
+ $('#' + this.containerId).remove()
89
+ }
90
+
91
+ jasmine.Fixtures.prototype.sandbox = function (attributes) {
92
+ var attributesToSet = attributes || {}
93
+ return $('<div id="sandbox" />').attr(attributesToSet)
94
+ }
95
+
96
+ jasmine.Fixtures.prototype.createContainer_ = function (html) {
97
+ var container = $('<div>')
98
+ .attr('id', this.containerId)
99
+ .html(html)
100
+
101
+ $(document.body).append(container)
102
+ return container
103
+ }
104
+
105
+ jasmine.Fixtures.prototype.addToContainer_ = function (html){
106
+ var container = $(document.body).find('#'+this.containerId).append(html)
107
+
108
+ if (!container.length) {
109
+ this.createContainer_(html)
110
+ }
111
+ }
112
+
113
+ jasmine.Fixtures.prototype.getFixtureHtml_ = function (url) {
114
+ if (typeof this.fixturesCache_[url] === 'undefined') {
115
+ this.loadFixtureIntoCache_(url)
116
+ }
117
+ return this.fixturesCache_[url]
118
+ }
119
+
120
+ jasmine.Fixtures.prototype.loadFixtureIntoCache_ = function (relativeUrl) {
121
+ var self = this
122
+ , url = this.makeFixtureUrl_(relativeUrl)
123
+ , htmlText = ''
124
+ , request = $.ajax({
125
+ async: false, // must be synchronous to guarantee that no tests are run before fixture is loaded
126
+ cache: false,
127
+ url: url,
128
+ dataType: 'html',
129
+ success: function (data, status, $xhr) {
130
+ htmlText = $xhr.responseText
131
+ }
132
+ }).fail(function ($xhr, status, err) {
133
+ throw new Error('Fixture could not be loaded: ' + url + ' (status: ' + status + ', message: ' + err.message + ')')
134
+ })
135
+
136
+ var scripts = $($.parseHTML(htmlText, true)).find('script[src]') || [];
137
+
138
+ scripts.each(function(){
139
+ $.ajax({
140
+ async: false, // must be synchronous to guarantee that no tests are run before fixture is loaded
141
+ cache: false,
142
+ dataType: 'script',
143
+ url: $(this).attr('src'),
144
+ success: function (data, status, $xhr) {
145
+ htmlText += '<script>' + $xhr.responseText + '</script>'
146
+ },
147
+ error: function ($xhr, status, err) {
148
+ throw new Error('Script could not be loaded: ' + url + ' (status: ' + status + ', message: ' + err.message + ')')
149
+ }
150
+ });
151
+ })
152
+
153
+ self.fixturesCache_[relativeUrl] = htmlText;
154
+ }
155
+
156
+ jasmine.Fixtures.prototype.makeFixtureUrl_ = function (relativeUrl){
157
+ return this.fixturesPath.match('/$') ? this.fixturesPath + relativeUrl : this.fixturesPath + '/' + relativeUrl
158
+ }
159
+
160
+ jasmine.Fixtures.prototype.proxyCallTo_ = function (methodName, passedArguments) {
161
+ return this[methodName].apply(this, passedArguments)
162
+ }
163
+
164
+
165
+ jasmine.StyleFixtures = function () {
166
+ this.fixturesCache_ = {}
167
+ this.fixturesNodes_ = []
168
+ this.fixturesPath = 'spec/javascripts/fixtures'
169
+ }
170
+
171
+ jasmine.StyleFixtures.prototype.set = function (css) {
172
+ this.cleanUp()
173
+ this.createStyle_(css)
174
+ }
175
+
176
+ jasmine.StyleFixtures.prototype.appendSet = function (css) {
177
+ this.createStyle_(css)
178
+ }
179
+
180
+ jasmine.StyleFixtures.prototype.preload = function () {
181
+ this.read_.apply(this, arguments)
182
+ }
183
+
184
+ jasmine.StyleFixtures.prototype.load = function () {
185
+ this.cleanUp()
186
+ this.createStyle_(this.read_.apply(this, arguments))
187
+ }
188
+
189
+ jasmine.StyleFixtures.prototype.appendLoad = function () {
190
+ this.createStyle_(this.read_.apply(this, arguments))
191
+ }
192
+
193
+ jasmine.StyleFixtures.prototype.cleanUp = function () {
194
+ while(this.fixturesNodes_.length) {
195
+ this.fixturesNodes_.pop().remove()
196
+ }
197
+ }
198
+
199
+ jasmine.StyleFixtures.prototype.createStyle_ = function (html) {
200
+ var styleText = $('<div></div>').html(html).text()
201
+ , style = $('<style>' + styleText + '</style>')
202
+
203
+ this.fixturesNodes_.push(style)
204
+ $('head').append(style)
205
+ }
206
+
207
+ jasmine.StyleFixtures.prototype.clearCache = jasmine.Fixtures.prototype.clearCache
208
+ jasmine.StyleFixtures.prototype.read_ = jasmine.Fixtures.prototype.read
209
+ jasmine.StyleFixtures.prototype.getFixtureHtml_ = jasmine.Fixtures.prototype.getFixtureHtml_
210
+ jasmine.StyleFixtures.prototype.loadFixtureIntoCache_ = jasmine.Fixtures.prototype.loadFixtureIntoCache_
211
+ jasmine.StyleFixtures.prototype.makeFixtureUrl_ = jasmine.Fixtures.prototype.makeFixtureUrl_
212
+ jasmine.StyleFixtures.prototype.proxyCallTo_ = jasmine.Fixtures.prototype.proxyCallTo_
213
+
214
+ jasmine.getJSONFixtures = function () {
215
+ return jasmine.currentJSONFixtures_ = jasmine.currentJSONFixtures_ || new jasmine.JSONFixtures()
216
+ }
217
+
218
+ jasmine.JSONFixtures = function () {
219
+ this.fixturesCache_ = {}
220
+ this.fixturesPath = 'spec/javascripts/fixtures/json'
221
+ }
222
+
223
+ jasmine.JSONFixtures.prototype.load = function () {
224
+ this.read.apply(this, arguments)
225
+ return this.fixturesCache_
226
+ }
227
+
228
+ jasmine.JSONFixtures.prototype.read = function () {
229
+ var fixtureUrls = arguments
230
+
231
+ for(var urlCount = fixtureUrls.length, urlIndex = 0; urlIndex < urlCount; urlIndex++) {
232
+ this.getFixtureData_(fixtureUrls[urlIndex])
233
+ }
234
+
235
+ return this.fixturesCache_
236
+ }
237
+
238
+ jasmine.JSONFixtures.prototype.clearCache = function () {
239
+ this.fixturesCache_ = {}
240
+ }
241
+
242
+ jasmine.JSONFixtures.prototype.getFixtureData_ = function (url) {
243
+ if (!this.fixturesCache_[url]) this.loadFixtureIntoCache_(url)
244
+ return this.fixturesCache_[url]
245
+ }
246
+
247
+ jasmine.JSONFixtures.prototype.loadFixtureIntoCache_ = function (relativeUrl) {
248
+ var self = this
249
+ , url = this.fixturesPath.match('/$') ? this.fixturesPath + relativeUrl : this.fixturesPath + '/' + relativeUrl
250
+
251
+ $.ajax({
252
+ async: false, // must be synchronous to guarantee that no tests are run before fixture is loaded
253
+ cache: false,
254
+ dataType: 'json',
255
+ url: url,
256
+ success: function (data) {
257
+ self.fixturesCache_[relativeUrl] = data
258
+ },
259
+ error: function ($xhr, status, err) {
260
+ throw new Error('JSONFixture could not be loaded: ' + url + ' (status: ' + status + ', message: ' + err.message + ')')
261
+ }
262
+ })
263
+ }
264
+
265
+ jasmine.JSONFixtures.prototype.proxyCallTo_ = function (methodName, passedArguments) {
266
+ return this[methodName].apply(this, passedArguments)
267
+ }
268
+
269
+ jasmine.jQuery = function () {}
270
+
271
+ jasmine.jQuery.browserTagCaseIndependentHtml = function (html) {
272
+ return $('<div/>').append(html).html()
273
+ }
274
+
275
+ jasmine.jQuery.elementToString = function (element) {
276
+ return $(element).map(function () { return this.outerHTML; }).toArray().join(', ')
277
+ }
278
+
279
+ var data = {
280
+ spiedEvents: {}
281
+ , handlers: []
282
+ }
283
+
284
+ jasmine.jQuery.events = {
285
+ spyOn: function (selector, eventName) {
286
+ var handler = function (e) {
287
+ var calls = (typeof data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)] !== 'undefined') ? data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)].calls : 0
288
+ data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)] = {
289
+ args: jasmine.util.argsToArray(arguments),
290
+ calls: ++calls
291
+ }
292
+ }
293
+
294
+ $(selector).on(eventName, handler)
295
+ data.handlers.push(handler)
296
+
297
+ return {
298
+ selector: selector,
299
+ eventName: eventName,
300
+ handler: handler,
301
+ reset: function (){
302
+ delete data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)]
303
+ },
304
+ calls: {
305
+ count: function () {
306
+ return data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)] ?
307
+ data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)].calls : 0;
308
+ },
309
+ any: function () {
310
+ return data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)] ?
311
+ !!data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)].calls : false;
312
+ }
313
+ }
314
+ }
315
+ },
316
+
317
+ args: function (selector, eventName) {
318
+ var actualArgs = data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)].args
319
+
320
+ if (!actualArgs) {
321
+ throw "There is no spy for " + eventName + " on " + selector.toString() + ". Make sure to create a spy using spyOnEvent."
322
+ }
323
+
324
+ return actualArgs
325
+ },
326
+
327
+ wasTriggered: function (selector, eventName) {
328
+ return !!(data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)])
329
+ },
330
+
331
+ wasTriggeredWith: function (selector, eventName, expectedArgs, util, customEqualityTesters) {
332
+ var actualArgs = jasmine.jQuery.events.args(selector, eventName).slice(1)
333
+
334
+ if (Object.prototype.toString.call(expectedArgs) !== '[object Array]')
335
+ actualArgs = actualArgs[0]
336
+
337
+ return util.equals(actualArgs, expectedArgs, customEqualityTesters)
338
+ },
339
+
340
+ wasPrevented: function (selector, eventName) {
341
+ var spiedEvent = data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)]
342
+ , args = (jasmine.util.isUndefined(spiedEvent)) ? {} : spiedEvent.args
343
+ , e = args ? args[0] : undefined
344
+
345
+ return e && e.isDefaultPrevented()
346
+ },
347
+
348
+ wasStopped: function (selector, eventName) {
349
+ var spiedEvent = data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)]
350
+ , args = (jasmine.util.isUndefined(spiedEvent)) ? {} : spiedEvent.args
351
+ , e = args ? args[0] : undefined
352
+
353
+ return e && e.isPropagationStopped()
354
+ },
355
+
356
+ cleanUp: function () {
357
+ data.spiedEvents = {}
358
+ data.handlers = []
359
+ }
360
+ }
361
+
362
+ var hasProperty = function (actualValue, expectedValue) {
363
+ if (expectedValue === undefined)
364
+ return actualValue !== undefined
365
+
366
+ return actualValue === expectedValue
367
+ }
368
+
369
+ beforeEach(function () {
370
+ jasmine.addMatchers({
371
+ toHaveClass: function () {
372
+ return {
373
+ compare: function (actual, className) {
374
+ return { pass: $(actual).hasClass(className) }
375
+ }
376
+ }
377
+ },
378
+
379
+ toHaveCss: function () {
380
+ return {
381
+ compare: function (actual, css) {
382
+ for (var prop in css){
383
+ var value = css[prop]
384
+ // see issue #147 on gh
385
+ ;if (value === 'auto' && $(actual).get(0).style[prop] === 'auto') continue
386
+ if ($(actual).css(prop) !== value) return { pass: false }
387
+ }
388
+ return { pass: true }
389
+ }
390
+ }
391
+ },
392
+
393
+ toBeVisible: function () {
394
+ return {
395
+ compare: function (actual) {
396
+ return { pass: $(actual).is(':visible') }
397
+ }
398
+ }
399
+ },
400
+
401
+ toBeHidden: function () {
402
+ return {
403
+ compare: function (actual) {
404
+ return { pass: $(actual).is(':hidden') }
405
+ }
406
+ }
407
+ },
408
+
409
+ toBeSelected: function () {
410
+ return {
411
+ compare: function (actual) {
412
+ return { pass: $(actual).is(':selected') }
413
+ }
414
+ }
415
+ },
416
+
417
+ toBeChecked: function () {
418
+ return {
419
+ compare: function (actual) {
420
+ return { pass: $(actual).is(':checked') }
421
+ }
422
+ }
423
+ },
424
+
425
+ toBeEmpty: function () {
426
+ return {
427
+ compare: function (actual) {
428
+ return { pass: $(actual).is(':empty') }
429
+ }
430
+ }
431
+ },
432
+
433
+ toBeInDOM: function () {
434
+ return {
435
+ compare: function (actual) {
436
+ return { pass: $.contains(document.documentElement, $(actual)[0]) }
437
+ }
438
+ }
439
+ },
440
+
441
+ toExist: function () {
442
+ return {
443
+ compare: function (actual) {
444
+ return { pass: $(actual).length }
445
+ }
446
+ }
447
+ },
448
+
449
+ toHaveLength: function () {
450
+ return {
451
+ compare: function (actual, length) {
452
+ return { pass: $(actual).length === length }
453
+ }
454
+ }
455
+ },
456
+
457
+ toHaveAttr: function () {
458
+ return {
459
+ compare: function (actual, attributeName, expectedAttributeValue) {
460
+ return { pass: hasProperty($(actual).attr(attributeName), expectedAttributeValue) }
461
+ }
462
+ }
463
+ },
464
+
465
+ toHaveProp: function () {
466
+ return {
467
+ compare: function (actual, propertyName, expectedPropertyValue) {
468
+ return { pass: hasProperty($(actual).prop(propertyName), expectedPropertyValue) }
469
+ }
470
+ }
471
+ },
472
+
473
+ toHaveId: function () {
474
+ return {
475
+ compare: function (actual, id) {
476
+ return { pass: $(actual).attr('id') == id }
477
+ }
478
+ }
479
+ },
480
+
481
+ toHaveHtml: function () {
482
+ return {
483
+ compare: function (actual, html) {
484
+ return { pass: $(actual).html() == jasmine.jQuery.browserTagCaseIndependentHtml(html) }
485
+ }
486
+ }
487
+ },
488
+
489
+ toContainHtml: function () {
490
+ return {
491
+ compare: function (actual, html) {
492
+ var actualHtml = $(actual).html()
493
+ , expectedHtml = jasmine.jQuery.browserTagCaseIndependentHtml(html)
494
+
495
+ return { pass: (actualHtml.indexOf(expectedHtml) >= 0) }
496
+ }
497
+ }
498
+ },
499
+
500
+ toHaveText: function () {
501
+ return {
502
+ compare: function (actual, text) {
503
+ var actualText = $(actual).text()
504
+ var trimmedText = $.trim(actualText)
505
+
506
+ if (text && $.isFunction(text.test)) {
507
+ return { pass: text.test(actualText) || text.test(trimmedText) }
508
+ } else {
509
+ return { pass: (actualText == text || trimmedText == text) }
510
+ }
511
+ }
512
+ }
513
+ },
514
+
515
+ toContainText: function () {
516
+ return {
517
+ compare: function (actual, text) {
518
+ var trimmedText = $.trim($(actual).text())
519
+
520
+ if (text && $.isFunction(text.test)) {
521
+ return { pass: text.test(trimmedText) }
522
+ } else {
523
+ return { pass: trimmedText.indexOf(text) != -1 }
524
+ }
525
+ }
526
+ }
527
+ },
528
+
529
+ toHaveValue: function () {
530
+ return {
531
+ compare: function (actual, value) {
532
+ return { pass: $(actual).val() === value }
533
+ }
534
+ }
535
+ },
536
+
537
+ toHaveData: function () {
538
+ return {
539
+ compare: function (actual, key, expectedValue) {
540
+ return { pass: hasProperty($(actual).data(key), expectedValue) }
541
+ }
542
+ }
543
+ },
544
+
545
+ toContainElement: function () {
546
+ return {
547
+ compare: function (actual, selector) {
548
+ return { pass: $(actual).find(selector).length }
549
+ }
550
+ }
551
+ },
552
+
553
+ toBeMatchedBy: function () {
554
+ return {
555
+ compare: function (actual, selector) {
556
+ return { pass: $(actual).filter(selector).length }
557
+ }
558
+ }
559
+ },
560
+
561
+ toBeDisabled: function () {
562
+ return {
563
+ compare: function (actual, selector) {
564
+ return { pass: $(actual).is(':disabled') }
565
+ }
566
+ }
567
+ },
568
+
569
+ toBeFocused: function (selector) {
570
+ return {
571
+ compare: function (actual, selector) {
572
+ return { pass: $(actual)[0] === $(actual)[0].ownerDocument.activeElement }
573
+ }
574
+ }
575
+ },
576
+
577
+ toHandle: function () {
578
+ return {
579
+ compare: function (actual, event) {
580
+ if ( !actual || actual.length === 0 ) return { pass: false };
581
+ var events = $._data($(actual).get(0), "events")
582
+
583
+ if (!events || !event || typeof event !== "string") {
584
+ return { pass: false }
585
+ }
586
+
587
+ var namespaces = event.split(".")
588
+ , eventType = namespaces.shift()
589
+ , sortedNamespaces = namespaces.slice(0).sort()
590
+ , namespaceRegExp = new RegExp("(^|\\.)" + sortedNamespaces.join("\\.(?:.*\\.)?") + "(\\.|$)")
591
+
592
+ if (events[eventType] && namespaces.length) {
593
+ for (var i = 0; i < events[eventType].length; i++) {
594
+ var namespace = events[eventType][i].namespace
595
+
596
+ if (namespaceRegExp.test(namespace))
597
+ return { pass: true }
598
+ }
599
+ } else {
600
+ return { pass: (events[eventType] && events[eventType].length > 0) }
601
+ }
602
+
603
+ return { pass: false }
604
+ }
605
+ }
606
+ },
607
+
608
+ toHandleWith: function () {
609
+ return {
610
+ compare: function (actual, eventName, eventHandler) {
611
+ if ( !actual || actual.length === 0 ) return { pass: false };
612
+ var normalizedEventName = eventName.split('.')[0]
613
+ , stack = $._data($(actual).get(0), "events")[normalizedEventName]
614
+
615
+ for (var i = 0; i < stack.length; i++) {
616
+ if (stack[i].handler == eventHandler) return { pass: true }
617
+ }
618
+
619
+ return { pass: false }
620
+ }
621
+ }
622
+ },
623
+
624
+ toHaveBeenTriggeredOn: function () {
625
+ return {
626
+ compare: function (actual, selector) {
627
+ var result = { pass: jasmine.jQuery.events.wasTriggered(selector, actual) }
628
+
629
+ result.message = result.pass ?
630
+ "Expected event " + $(actual) + " not to have been triggered on " + selector :
631
+ "Expected event " + $(actual) + " to have been triggered on " + selector
632
+
633
+ return result;
634
+ }
635
+ }
636
+ },
637
+
638
+ toHaveBeenTriggered: function (){
639
+ return {
640
+ compare: function (actual) {
641
+ var eventName = actual.eventName
642
+ , selector = actual.selector
643
+ , result = { pass: jasmine.jQuery.events.wasTriggered(selector, eventName) }
644
+
645
+ result.message = result.pass ?
646
+ "Expected event " + eventName + " not to have been triggered on " + selector :
647
+ "Expected event " + eventName + " to have been triggered on " + selector
648
+
649
+ return result
650
+ }
651
+ }
652
+ },
653
+
654
+ toHaveBeenTriggeredOnAndWith: function (j$, customEqualityTesters) {
655
+ return {
656
+ compare: function (actual, selector, expectedArgs) {
657
+ var wasTriggered = jasmine.jQuery.events.wasTriggered(selector, actual)
658
+ , result = { pass: wasTriggered && jasmine.jQuery.events.wasTriggeredWith(selector, actual, expectedArgs, j$, customEqualityTesters) }
659
+
660
+ if (wasTriggered) {
661
+ var actualArgs = jasmine.jQuery.events.args(selector, actual, expectedArgs)[1]
662
+ result.message = result.pass ?
663
+ "Expected event " + actual + " not to have been triggered with " + jasmine.pp(expectedArgs) + " but it was triggered with " + jasmine.pp(actualArgs) :
664
+ "Expected event " + actual + " to have been triggered with " + jasmine.pp(expectedArgs) + " but it was triggered with " + jasmine.pp(actualArgs)
665
+
666
+ } else {
667
+ // todo check on this
668
+ result.message = result.pass ?
669
+ "Expected event " + actual + " not to have been triggered on " + selector :
670
+ "Expected event " + actual + " to have been triggered on " + selector
671
+ }
672
+
673
+ return result
674
+ }
675
+ }
676
+ },
677
+
678
+ toHaveBeenPreventedOn: function () {
679
+ return {
680
+ compare: function (actual, selector) {
681
+ var result = { pass: jasmine.jQuery.events.wasPrevented(selector, actual) }
682
+
683
+ result.message = result.pass ?
684
+ "Expected event " + actual + " not to have been prevented on " + selector :
685
+ "Expected event " + actual + " to have been prevented on " + selector
686
+
687
+ return result
688
+ }
689
+ }
690
+ },
691
+
692
+ toHaveBeenPrevented: function () {
693
+ return {
694
+ compare: function (actual) {
695
+ var eventName = actual.eventName
696
+ , selector = actual.selector
697
+ , result = { pass: jasmine.jQuery.events.wasPrevented(selector, eventName) }
698
+
699
+ result.message = result.pass ?
700
+ "Expected event " + eventName + " not to have been prevented on " + selector :
701
+ "Expected event " + eventName + " to have been prevented on " + selector
702
+
703
+ return result
704
+ }
705
+ }
706
+ },
707
+
708
+ toHaveBeenStoppedOn: function () {
709
+ return {
710
+ compare: function (actual, selector) {
711
+ var result = { pass: jasmine.jQuery.events.wasStopped(selector, actual) }
712
+
713
+ result.message = result.pass ?
714
+ "Expected event " + actual + " not to have been stopped on " + selector :
715
+ "Expected event " + actual + " to have been stopped on " + selector
716
+
717
+ return result;
718
+ }
719
+ }
720
+ },
721
+
722
+ toHaveBeenStopped: function () {
723
+ return {
724
+ compare: function (actual) {
725
+ var eventName = actual.eventName
726
+ , selector = actual.selector
727
+ , result = { pass: jasmine.jQuery.events.wasStopped(selector, eventName) }
728
+
729
+ result.message = result.pass ?
730
+ "Expected event " + eventName + " not to have been stopped on " + selector :
731
+ "Expected event " + eventName + " to have been stopped on " + selector
732
+
733
+ return result
734
+ }
735
+ }
736
+ }
737
+ })
738
+
739
+ jasmine.getEnv().addCustomEqualityTester(function(a, b) {
740
+ if (a && b) {
741
+ if (a instanceof $ || jasmine.isDomNode(a)) {
742
+ var $a = $(a)
743
+
744
+ if (b instanceof $)
745
+ return $a.length == b.length && a.is(b)
746
+
747
+ return $a.is(b);
748
+ }
749
+
750
+ if (b instanceof $ || jasmine.isDomNode(b)) {
751
+ var $b = $(b)
752
+
753
+ if (a instanceof $)
754
+ return a.length == $b.length && $b.is(a)
755
+
756
+ return $(b).is(a);
757
+ }
758
+ }
759
+ })
760
+
761
+ jasmine.getEnv().addCustomEqualityTester(function (a, b) {
762
+ if (a instanceof $ && b instanceof $ && a.size() == b.size())
763
+ return a.is(b)
764
+ })
765
+ })
766
+
767
+ afterEach(function () {
768
+ jasmine.getFixtures().cleanUp()
769
+ jasmine.getStyleFixtures().cleanUp()
770
+ jasmine.jQuery.events.cleanUp()
771
+ })
772
+
773
+ window.readFixtures = function () {
774
+ return jasmine.getFixtures().proxyCallTo_('read', arguments)
775
+ }
776
+
777
+ window.preloadFixtures = function () {
778
+ jasmine.getFixtures().proxyCallTo_('preload', arguments)
779
+ }
780
+
781
+ window.loadFixtures = function () {
782
+ jasmine.getFixtures().proxyCallTo_('load', arguments)
783
+ }
784
+
785
+ window.appendLoadFixtures = function () {
786
+ jasmine.getFixtures().proxyCallTo_('appendLoad', arguments)
787
+ }
788
+
789
+ window.setFixtures = function (html) {
790
+ return jasmine.getFixtures().proxyCallTo_('set', arguments)
791
+ }
792
+
793
+ window.appendSetFixtures = function () {
794
+ jasmine.getFixtures().proxyCallTo_('appendSet', arguments)
795
+ }
796
+
797
+ window.sandbox = function (attributes) {
798
+ return jasmine.getFixtures().sandbox(attributes)
799
+ }
800
+
801
+ window.spyOnEvent = function (selector, eventName) {
802
+ return jasmine.jQuery.events.spyOn(selector, eventName)
803
+ }
804
+
805
+ window.preloadStyleFixtures = function () {
806
+ jasmine.getStyleFixtures().proxyCallTo_('preload', arguments)
807
+ }
808
+
809
+ window.loadStyleFixtures = function () {
810
+ jasmine.getStyleFixtures().proxyCallTo_('load', arguments)
811
+ }
812
+
813
+ window.appendLoadStyleFixtures = function () {
814
+ jasmine.getStyleFixtures().proxyCallTo_('appendLoad', arguments)
815
+ }
816
+
817
+ window.setStyleFixtures = function (html) {
818
+ jasmine.getStyleFixtures().proxyCallTo_('set', arguments)
819
+ }
820
+
821
+ window.appendSetStyleFixtures = function (html) {
822
+ jasmine.getStyleFixtures().proxyCallTo_('appendSet', arguments)
823
+ }
824
+
825
+ window.loadJSONFixtures = function () {
826
+ return jasmine.getJSONFixtures().proxyCallTo_('load', arguments)
827
+ }
828
+
829
+ window.getJSONFixture = function (url) {
830
+ return jasmine.getJSONFixtures().proxyCallTo_('read', arguments)[url]
831
+ }
832
+ }(window, window.jasmine, window.jQuery);