jasmine-jquery-rails 1.5.9 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: da4c21bea3d761fbf0cfb01e25af8ae03005a893
4
- data.tar.gz: dda8eabbc7b390904a555042905dd24b0522a454
3
+ metadata.gz: c3586de1a3e0f7d2e160bffc4fe8bc38fd0b49b7
4
+ data.tar.gz: d5d38ca8d7c32c6e87720c49fda85a9af0f9f51a
5
5
  SHA512:
6
- metadata.gz: 2446540a0e916a16cbc29db9b086df18e6733b4406d32452675e06bf25a26d63a38d84bd64bece3f74075047f36e9f8e74073d3aacef33dec37eb9bcb878a995
7
- data.tar.gz: fbe32b410456ac91663d3ef6055702a0c73bc55052a578833aa404d3e43999e0fd3fee33b16ad05b99123ab337cad03bdcb18f43d93ae3fb79eaab3935c1919b
6
+ metadata.gz: b0230afceba722243a2951698c9fdc404fbc377d7d300d80076665be7152c362e8a741dc31acbc326ae7f56300da9f69d3d39ef2abd270999116bb53f37229df
7
+ data.tar.gz: e8008fe6f78d14dcb07e558293cc8d01ea15a1be0df95663c3a3c80b495edb108c3aa0e718c6718fe7bfbde64384f9b4a0b146441c92cba2e8fbb8e4c82316d8
@@ -1,7 +1,7 @@
1
1
  module Jasmine
2
2
  module Jquery
3
3
  module Rails
4
- VERSION = "1.5.9"
4
+ VERSION = "2.0.2"
5
5
  end
6
6
  end
7
7
  end
@@ -1,11 +1,11 @@
1
1
  /*!
2
2
  Jasmine-jQuery: a set of jQuery helpers for Jasmine tests.
3
3
 
4
- Version 1.5.9
4
+ Version 2.0.2
5
5
 
6
6
  https://github.com/velesin/jasmine-jquery
7
7
 
8
- Copyright (c) 2010-2013 Wojciech Zawistowski, Travis Jeffery
8
+ Copyright (c) 2010-2014 Wojciech Zawistowski, Travis Jeffery
9
9
 
10
10
  Permission is hereby granted, free of charge, to any person obtaining
11
11
  a copy of this software and associated documentation files (the
@@ -27,7 +27,7 @@ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27
27
  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28
28
  */
29
29
 
30
- +function (jasmine, $) { "use strict";
30
+ +function (window, jasmine, $) { "use strict";
31
31
 
32
32
  jasmine.spiedEventsKey = function (selector, eventName) {
33
33
  return [$(selector).selector, eventName].toString()
@@ -104,7 +104,8 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
104
104
 
105
105
  jasmine.Fixtures.prototype.addToContainer_ = function (html){
106
106
  var container = $(document.body).find('#'+this.containerId).append(html)
107
- if(!container.length){
107
+
108
+ if (!container.length) {
108
109
  this.createContainer_(html)
109
110
  }
110
111
  }
@@ -119,17 +120,36 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
119
120
  jasmine.Fixtures.prototype.loadFixtureIntoCache_ = function (relativeUrl) {
120
121
  var self = this
121
122
  , url = this.makeFixtureUrl_(relativeUrl)
123
+ , htmlText = ''
122
124
  , request = $.ajax({
123
125
  async: false, // must be synchronous to guarantee that no tests are run before fixture is loaded
124
126
  cache: false,
125
127
  url: url,
126
128
  success: function (data, status, $xhr) {
127
- self.fixturesCache_[relativeUrl] = $xhr.responseText
128
- },
129
- error: function (jqXHR, status, errorThrown) {
130
- throw new Error('Fixture could not be loaded: ' + url + ' (status: ' + status + ', message: ' + errorThrown.message + ')')
129
+ htmlText = $xhr.responseText
131
130
  }
131
+ }).fail(function () {
132
+ throw new Error('Fixture could not be loaded: ' + url + ' (status: ' + status + ', message: ' + errorThrown.message + ')')
133
+ })
134
+
135
+ var scripts = $($.parseHTML(htmlText, true)).find('script[src]') || [];
136
+
137
+ scripts.each(function(){
138
+ $.ajax({
139
+ async: false, // must be synchronous to guarantee that no tests are run before fixture is loaded
140
+ cache: false,
141
+ dataType: 'script',
142
+ url: $(this).attr('src'),
143
+ success: function (data, status, $xhr) {
144
+ htmlText += '<script>' + $xhr.responseText + '</script>'
145
+ },
146
+ error: function (jqXHR, status, errorThrown) {
147
+ throw new Error('Script could not be loaded: ' + scriptSrc + ' (status: ' + status + ', message: ' + errorThrown.message + ')')
148
+ }
149
+ });
132
150
  })
151
+
152
+ self.fixturesCache_[relativeUrl] = htmlText;
133
153
  }
134
154
 
135
155
  jasmine.Fixtures.prototype.makeFixtureUrl_ = function (relativeUrl){
@@ -219,7 +239,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
219
239
  }
220
240
 
221
241
  jasmine.JSONFixtures.prototype.getFixtureData_ = function (url) {
222
- this.loadFixtureIntoCache_(url)
242
+ if (!this.fixturesCache_[url]) this.loadFixtureIntoCache_(url)
223
243
  return this.fixturesCache_[url]
224
244
  }
225
245
 
@@ -245,461 +265,549 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
245
265
  return this[methodName].apply(this, passedArguments)
246
266
  }
247
267
 
248
- jasmine.JQuery = function () {}
268
+ jasmine.jQuery = function () {}
249
269
 
250
- jasmine.JQuery.browserTagCaseIndependentHtml = function (html) {
270
+ jasmine.jQuery.browserTagCaseIndependentHtml = function (html) {
251
271
  return $('<div/>').append(html).html()
252
272
  }
253
273
 
254
- jasmine.JQuery.elementToString = function (element) {
255
- var domEl = $(element).get(0)
274
+ jasmine.jQuery.elementToString = function (element) {
275
+ return $(element).map(function () { return this.outerHTML; }).toArray().join(', ')
276
+ }
256
277
 
257
- if (domEl === undefined || domEl.cloneNode)
258
- return $('<div />').append($(element).clone()).html()
259
- else
260
- return element.toString()
278
+ var data = {
279
+ spiedEvents: {}
280
+ , handlers: []
261
281
  }
262
282
 
263
- jasmine.JQuery.matchersClass = {}
283
+ jasmine.jQuery.events = {
284
+ spyOn: function (selector, eventName) {
285
+ var handler = function (e) {
286
+ data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)] = jasmine.util.argsToArray(arguments)
287
+ }
264
288
 
265
- !function (namespace) {
266
- var data = {
267
- spiedEvents: {}
268
- , handlers: []
269
- }
289
+ $(selector).on(eventName, handler)
290
+ data.handlers.push(handler)
270
291
 
271
- namespace.events = {
272
- spyOn: function (selector, eventName) {
273
- var handler = function (e) {
274
- data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)] = jasmine.util.argsToArray(arguments)
292
+ return {
293
+ selector: selector,
294
+ eventName: eventName,
295
+ handler: handler,
296
+ reset: function (){
297
+ delete data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)]
275
298
  }
299
+ }
300
+ },
276
301
 
277
- $(selector).on(eventName, handler)
278
- data.handlers.push(handler)
302
+ args: function (selector, eventName) {
303
+ var actualArgs = data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)]
279
304
 
280
- return {
281
- selector: selector,
282
- eventName: eventName,
283
- handler: handler,
284
- reset: function (){
285
- delete data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)]
286
- }
287
- }
288
- },
305
+ if (!actualArgs) {
306
+ throw "There is no spy for " + eventName + " on " + selector.toString() + ". Make sure to create a spy using spyOnEvent."
307
+ }
289
308
 
290
- args: function (selector, eventName) {
291
- var actualArgs = data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)]
309
+ return actualArgs
310
+ },
292
311
 
293
- if (!actualArgs) {
294
- throw "There is no spy for " + eventName + " on " + selector.toString() + ". Make sure to create a spy using spyOnEvent."
295
- }
312
+ wasTriggered: function (selector, eventName) {
313
+ return !!(data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)])
314
+ },
296
315
 
297
- return actualArgs
298
- },
316
+ wasTriggeredWith: function (selector, eventName, expectedArgs, util, customEqualityTesters) {
317
+ var actualArgs = jasmine.jQuery.events.args(selector, eventName).slice(1)
299
318
 
300
- wasTriggered: function (selector, eventName) {
301
- return !!(data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)])
302
- },
319
+ if (Object.prototype.toString.call(expectedArgs) !== '[object Array]')
320
+ actualArgs = actualArgs[0]
303
321
 
304
- wasTriggeredWith: function (selector, eventName, expectedArgs, env) {
305
- var actualArgs = jasmine.JQuery.events.args(selector, eventName).slice(1)
306
- if (Object.prototype.toString.call(expectedArgs) !== '[object Array]') {
307
- actualArgs = actualArgs[0]
308
- }
309
- return env.equals_(expectedArgs, actualArgs)
310
- },
322
+ return util.equals(expectedArgs, actualArgs, customEqualityTesters)
323
+ },
311
324
 
312
- wasPrevented: function (selector, eventName) {
313
- var args = data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)]
314
- , e = args ? args[0] : undefined
325
+ wasPrevented: function (selector, eventName) {
326
+ var args = data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)]
327
+ , e = args ? args[0] : undefined
315
328
 
316
- return e && e.isDefaultPrevented()
317
- },
329
+ return e && e.isDefaultPrevented()
330
+ },
318
331
 
319
- wasStopped: function (selector, eventName) {
320
- var args = data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)]
321
- , e = args ? args[0] : undefined
322
- return e && e.isPropagationStopped()
323
- },
332
+ wasStopped: function (selector, eventName) {
333
+ var args = data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)]
334
+ , e = args ? args[0] : undefined
335
+ return e && e.isPropagationStopped()
336
+ },
324
337
 
325
- cleanUp: function () {
326
- data.spiedEvents = {}
327
- data.handlers = []
328
- }
338
+ cleanUp: function () {
339
+ data.spiedEvents = {}
340
+ data.handlers = []
329
341
  }
330
- }(jasmine.JQuery)
342
+ }
343
+
344
+ var hasProperty = function (actualValue, expectedValue) {
345
+ if (expectedValue === undefined)
346
+ return actualValue !== undefined
331
347
 
332
- !function (){
333
- var jQueryMatchers = {
334
- toHaveClass: function (className) {
335
- return this.actual.hasClass(className)
348
+ return actualValue === expectedValue
349
+ }
350
+
351
+ beforeEach(function () {
352
+ jasmine.addMatchers({
353
+ toHaveClass: function () {
354
+ return {
355
+ compare: function (actual, className) {
356
+ return { pass: $(actual).hasClass(className) }
357
+ }
358
+ }
336
359
  },
337
360
 
338
- toHaveCss: function (css){
339
- for (var prop in css){
340
- var value = css[prop]
341
- // see issue #147 on gh
342
- ;if (value === 'auto' && this.actual.get(0).style[prop] === 'auto') continue
343
- if (this.actual.css(prop) !== value) return false
361
+ toHaveCss: function () {
362
+ return {
363
+ compare: function (actual, css) {
364
+ for (var prop in css){
365
+ var value = css[prop]
366
+ // see issue #147 on gh
367
+ ;if (value === 'auto' && $(actual).get(0).style[prop] === 'auto') continue
368
+ if ($(actual).css(prop) !== value) return { pass: false }
369
+ }
370
+ return { pass: true }
371
+ }
344
372
  }
345
- return true
346
373
  },
347
374
 
348
375
  toBeVisible: function () {
349
- return this.actual.is(':visible')
376
+ return {
377
+ compare: function (actual) {
378
+ return { pass: $(actual).is(':visible') }
379
+ }
380
+ }
350
381
  },
351
382
 
352
383
  toBeHidden: function () {
353
- return this.actual.is(':hidden')
384
+ return {
385
+ compare: function (actual) {
386
+ return { pass: $(actual).is(':hidden') }
387
+ }
388
+ }
354
389
  },
355
390
 
356
391
  toBeSelected: function () {
357
- return this.actual.is(':selected')
392
+ return {
393
+ compare: function (actual) {
394
+ return { pass: $(actual).is(':selected') }
395
+ }
396
+ }
358
397
  },
359
398
 
360
399
  toBeChecked: function () {
361
- return this.actual.is(':checked')
400
+ return {
401
+ compare: function (actual) {
402
+ return { pass: $(actual).is(':checked') }
403
+ }
404
+ }
362
405
  },
363
406
 
364
407
  toBeEmpty: function () {
365
- return this.actual.is(':empty')
408
+ return {
409
+ compare: function (actual) {
410
+ return { pass: $(actual).is(':empty') }
411
+ }
412
+ }
366
413
  },
367
414
 
368
- toExist: function () {
369
- return this.actual.length
415
+ toBeInDOM: function () {
416
+ return {
417
+ compare: function (actual) {
418
+ return { pass: $.contains(document.documentElement, $(actual)[0]) }
419
+ }
420
+ }
370
421
  },
371
422
 
372
- toHaveLength: function (length) {
373
- return this.actual.length === length
423
+ toExist: function () {
424
+ return {
425
+ compare: function (actual) {
426
+ return { pass: $(actual).length }
427
+ }
428
+ }
374
429
  },
375
430
 
376
- toHaveAttr: function (attributeName, expectedAttributeValue) {
377
- return hasProperty(this.actual.attr(attributeName), expectedAttributeValue)
431
+ toHaveLength: function () {
432
+ return {
433
+ compare: function (actual, length) {
434
+ return { pass: $(actual).length === length }
435
+ }
436
+ }
378
437
  },
379
438
 
380
- toHaveProp: function (propertyName, expectedPropertyValue) {
381
- return hasProperty(this.actual.prop(propertyName), expectedPropertyValue)
439
+ toHaveAttr: function () {
440
+ return {
441
+ compare: function (actual, attributeName, expectedAttributeValue) {
442
+ return { pass: hasProperty($(actual).attr(attributeName), expectedAttributeValue) }
443
+ }
444
+ }
382
445
  },
383
446
 
384
- toHaveId: function (id) {
385
- return this.actual.attr('id') == id
447
+ toHaveProp: function () {
448
+ return {
449
+ compare: function (actual, propertyName, expectedPropertyValue) {
450
+ return { pass: hasProperty($(actual).prop(propertyName), expectedPropertyValue) }
451
+ }
452
+ }
386
453
  },
387
454
 
388
- toHaveHtml: function (html) {
389
- return this.actual.html() == jasmine.JQuery.browserTagCaseIndependentHtml(html)
455
+ toHaveId: function () {
456
+ return {
457
+ compare: function (actual, id) {
458
+ return { pass: $(actual).attr('id') == id }
459
+ }
460
+ }
390
461
  },
391
462
 
392
- toContainHtml: function (html){
393
- var actualHtml = this.actual.html()
394
- , expectedHtml = jasmine.JQuery.browserTagCaseIndependentHtml(html)
395
-
396
- return (actualHtml.indexOf(expectedHtml) >= 0)
463
+ toHaveHtml: function () {
464
+ return {
465
+ compare: function (actual, html) {
466
+ return { pass: $(actual).html() == jasmine.jQuery.browserTagCaseIndependentHtml(html) }
467
+ }
468
+ }
397
469
  },
398
470
 
399
- toHaveText: function (text) {
400
- var trimmedText = $.trim(this.actual.text())
471
+ toContainHtml: function () {
472
+ return {
473
+ compare: function (actual, html) {
474
+ var actualHtml = $(actual).html()
475
+ , expectedHtml = jasmine.jQuery.browserTagCaseIndependentHtml(html)
401
476
 
402
- if (text && $.isFunction(text.test)) {
403
- return text.test(trimmedText)
404
- } else {
405
- return trimmedText == text
477
+ return { pass: (actualHtml.indexOf(expectedHtml) >= 0) }
478
+ }
406
479
  }
407
480
  },
408
481
 
409
- toContainText: function (text) {
410
- var trimmedText = $.trim(this.actual.text())
482
+ toHaveText: function () {
483
+ return {
484
+ compare: function (actual, text) {
485
+ var trimmedText = $.trim($(actual).text())
411
486
 
412
- if (text && $.isFunction(text.test)) {
413
- return text.test(trimmedText)
414
- } else {
415
- return trimmedText.indexOf(text) != -1
487
+ if (text && $.isFunction(text.test)) {
488
+ return { pass: text.test(trimmedText) }
489
+ } else {
490
+ return { pass: trimmedText == text }
491
+ }
492
+ }
416
493
  }
417
494
  },
418
495
 
419
- toHaveValue: function (value) {
420
- return this.actual.val() === value
496
+ toContainText: function () {
497
+ return {
498
+ compare: function (actual, text) {
499
+ var trimmedText = $.trim($(actual).text())
500
+
501
+ if (text && $.isFunction(text.test)) {
502
+ return { pass: text.test(trimmedText) }
503
+ } else {
504
+ return { pass: trimmedText.indexOf(text) != -1 }
505
+ }
506
+ }
507
+ }
421
508
  },
422
509
 
423
- toHaveData: function (key, expectedValue) {
424
- return hasProperty(this.actual.data(key), expectedValue)
510
+ toHaveValue: function () {
511
+ return {
512
+ compare: function (actual, value) {
513
+ return { pass: $(actual).val() === value }
514
+ }
515
+ }
425
516
  },
426
517
 
427
- toBe: function (selector) {
428
- return this.actual.is(selector)
518
+ toHaveData: function () {
519
+ return {
520
+ compare: function (actual, key, expectedValue) {
521
+ return { pass: hasProperty($(actual).data(key), expectedValue) }
522
+ }
523
+ }
429
524
  },
430
525
 
431
- toContain: function (selector) {
432
- return this.actual.find(selector).length
526
+ toContainElement: function () {
527
+ return {
528
+ compare: function (actual, selector) {
529
+ if (window.debug) debugger
530
+ return { pass: $(actual).find(selector).length }
531
+ }
532
+ }
433
533
  },
434
534
 
435
- toBeMatchedBy: function (selector) {
436
- return this.actual.filter(selector).length
535
+ toBeMatchedBy: function () {
536
+ return {
537
+ compare: function (actual, selector) {
538
+ return { pass: $(actual).filter(selector).length }
539
+ }
540
+ }
437
541
  },
438
542
 
439
- toBeDisabled: function (selector){
440
- return this.actual.is(':disabled')
543
+ toBeDisabled: function () {
544
+ return {
545
+ compare: function (actual, selector) {
546
+ return { pass: $(actual).is(':disabled') }
547
+ }
548
+ }
441
549
  },
442
550
 
443
551
  toBeFocused: function (selector) {
444
- return this.actual[0] === this.actual[0].ownerDocument.activeElement
552
+ return {
553
+ compare: function (actual, selector) {
554
+ return { pass: $(actual)[0] === $(actual)[0].ownerDocument.activeElement }
555
+ }
556
+ }
445
557
  },
446
558
 
447
- toHandle: function (event) {
448
- var events = $._data(this.actual.get(0), "events")
559
+ toHandle: function () {
560
+ return {
561
+ compare: function (actual, event) {
562
+ var events = $._data($(actual).get(0), "events")
449
563
 
450
- if(!events || !event || typeof event !== "string") {
451
- return false
452
- }
564
+ if (!events || !event || typeof event !== "string") {
565
+ return { pass: false }
566
+ }
453
567
 
454
- var namespaces = event.split(".")
455
- , eventType = namespaces.shift()
456
- , sortedNamespaces = namespaces.slice(0).sort()
457
- , namespaceRegExp = new RegExp("(^|\\.)" + sortedNamespaces.join("\\.(?:.*\\.)?") + "(\\.|$)")
568
+ var namespaces = event.split(".")
569
+ , eventType = namespaces.shift()
570
+ , sortedNamespaces = namespaces.slice(0).sort()
571
+ , namespaceRegExp = new RegExp("(^|\\.)" + sortedNamespaces.join("\\.(?:.*\\.)?") + "(\\.|$)")
458
572
 
459
- if(events[eventType] && namespaces.length) {
460
- for(var i = 0; i < events[eventType].length; i++) {
461
- var namespace = events[eventType][i].namespace
573
+ if (events[eventType] && namespaces.length) {
574
+ for (var i = 0; i < events[eventType].length; i++) {
575
+ var namespace = events[eventType][i].namespace
462
576
 
463
- if(namespaceRegExp.test(namespace)) {
464
- return true
577
+ if (namespaceRegExp.test(namespace))
578
+ return { pass: true }
579
+ }
580
+ } else {
581
+ return { pass: (events[eventType] && events[eventType].length > 0) }
465
582
  }
583
+
584
+ return { pass: false }
466
585
  }
467
- } else {
468
- return events[eventType] && events[eventType].length > 0
469
586
  }
470
587
  },
471
588
 
472
- toHandleWith: function (eventName, eventHandler) {
473
- var normalizedEventName = eventName.split('.')[0]
474
- , stack = $._data(this.actual.get(0), "events")[normalizedEventName]
589
+ toHandleWith: function () {
590
+ return {
591
+ compare: function (actual, eventName, eventHandler) {
592
+ var normalizedEventName = eventName.split('.')[0]
593
+ , stack = $._data($(actual).get(0), "events")[normalizedEventName]
475
594
 
476
- for (var i = 0; i < stack.length; i++) {
477
- if (stack[i].handler == eventHandler) return true
595
+ for (var i = 0; i < stack.length; i++) {
596
+ if (stack[i].handler == eventHandler) return { pass: true }
597
+ }
598
+
599
+ return { pass: false }
600
+ }
478
601
  }
602
+ },
479
603
 
480
- return false
481
- }
482
- }
604
+ toHaveBeenTriggeredOn: function () {
605
+ return {
606
+ compare: function (actual, selector) {
607
+ var result = { pass: jasmine.jQuery.events.wasTriggered(selector, actual) }
483
608
 
484
- var hasProperty = function (actualValue, expectedValue) {
485
- if (expectedValue === undefined) return actualValue !== undefined
609
+ result.message = result.pass ?
610
+ "Expected event " + $(actual) + " not to have been triggered on " + selector :
611
+ "Expected event " + $(actual) + " to have been triggered on " + selector
486
612
 
487
- return actualValue == expectedValue
488
- }
613
+ return result;
614
+ }
615
+ }
616
+ },
489
617
 
490
- var bindMatcher = function (methodName) {
491
- var builtInMatcher = jasmine.Matchers.prototype[methodName]
618
+ toHaveBeenTriggered: function (){
619
+ return {
620
+ compare: function (actual) {
621
+ var eventName = actual.eventName
622
+ , selector = actual.selector
623
+ , result = { pass: jasmine.jQuery.events.wasTriggered(selector, eventName) }
624
+
625
+ result.message = result.pass ?
626
+ "Expected event " + eventName + " not to have been triggered on " + selector :
627
+ "Expected event " + eventName + " to have been triggered on " + selector
492
628
 
493
- jasmine.JQuery.matchersClass[methodName] = function () {
494
- if (this.actual
495
- && (this.actual instanceof $
496
- || jasmine.isDomNode(this.actual))) {
497
- this.actual = $(this.actual)
498
- var result = jQueryMatchers[methodName].apply(this, arguments)
499
- , element
629
+ return result
630
+ }
631
+ }
632
+ },
500
633
 
501
- if (this.actual.get && (element = this.actual.get()[0]) && !$.isWindow(element) && element.tagName !== "HTML")
502
- this.actual = jasmine.JQuery.elementToString(this.actual)
634
+ toHaveBeenTriggeredOnAndWith: function (j$, customEqualityTesters) {
635
+ return {
636
+ compare: function (actual, selector, expectedArgs) {
637
+ var wasTriggered = jasmine.jQuery.events.wasTriggered(selector, actual)
638
+ , result = { pass: wasTriggered && jasmine.jQuery.events.wasTriggeredWith(selector, actual, expectedArgs, j$, customEqualityTesters) }
639
+
640
+ if (wasTriggered) {
641
+ var actualArgs = jasmine.jQuery.events.args(selector, actual, expectedArgs)[1]
642
+ result.message = result.pass ?
643
+ "Expected event " + actual + " not to have been triggered with " + jasmine.pp(expectedArgs) + " but it was triggered with " + jasmine.pp(actualArgs) :
644
+ "Expected event " + actual + " to have been triggered with " + jasmine.pp(expectedArgs) + " but it was triggered with " + jasmine.pp(actualArgs)
645
+
646
+ } else {
647
+ // todo check on this
648
+ result.message = result.pass ?
649
+ "Expected event " + actual + " not to have been triggered on " + selector :
650
+ "Expected event " + actual + " to have been triggered on " + selector
651
+ }
503
652
 
504
653
  return result
505
- }
654
+ }
655
+ }
656
+ },
506
657
 
507
- if (builtInMatcher) {
508
- return builtInMatcher.apply(this, arguments)
509
- }
658
+ toHaveBeenPreventedOn: function () {
659
+ return {
660
+ compare: function (actual, selector) {
661
+ var result = { pass: jasmine.jQuery.events.wasPrevented(selector, actual) }
510
662
 
511
- return false
512
- }
513
- }
663
+ result.message = result.pass ?
664
+ "Expected event " + actual + " not to have been prevented on " + selector :
665
+ "Expected event " + actual + " to have been prevented on " + selector
514
666
 
515
- for(var methodName in jQueryMatchers) {
516
- bindMatcher(methodName)
517
- }
518
- }()
667
+ return result
668
+ }
669
+ }
670
+ },
519
671
 
520
- beforeEach(function () {
521
- this.addMatchers(jasmine.JQuery.matchersClass)
522
- this.addMatchers({
523
- toHaveBeenTriggeredOn: function (selector) {
524
- this.message = function () {
525
- return [
526
- "Expected event " + this.actual + " to have been triggered on " + selector,
527
- "Expected event " + this.actual + " not to have been triggered on " + selector
528
- ]
529
- }
530
- return jasmine.JQuery.events.wasTriggered(selector, this.actual)
531
- }
532
- })
533
- this.addMatchers({
534
- toHaveBeenTriggered: function (){
535
- var eventName = this.actual.eventName
536
- , selector = this.actual.selector
672
+ toHaveBeenPrevented: function () {
673
+ return {
674
+ compare: function (actual) {
675
+ var eventName = actual.eventName
676
+ , selector = actual.selector
677
+ , result = { pass: jasmine.jQuery.events.wasPrevented(selector, eventName) }
537
678
 
538
- this.message = function () {
539
- return [
540
- "Expected event " + eventName + " to have been triggered on " + selector,
541
- "Expected event " + eventName + " not to have been triggered on " + selector
542
- ]
543
- }
679
+ result.message = result.pass ?
680
+ "Expected event " + eventName + " not to have been prevented on " + selector :
681
+ "Expected event " + eventName + " to have been prevented on " + selector
544
682
 
545
- return jasmine.JQuery.events.wasTriggered(selector, eventName)
546
- }
547
- })
548
- this.addMatchers({
549
- toHaveBeenTriggeredOnAndWith: function () {
550
- var selector = arguments[0]
551
- , expectedArgs = arguments[1]
552
- , wasTriggered = jasmine.JQuery.events.wasTriggered(selector, this.actual)
553
-
554
- this.message = function () {
555
- if (wasTriggered) {
556
- var actualArgs = jasmine.JQuery.events.args(selector, this.actual, expectedArgs)[1]
557
- return [
558
- "Expected event " + this.actual + " to have been triggered with " + jasmine.pp(expectedArgs) + " but it was triggered with " + jasmine.pp(actualArgs),
559
- "Expected event " + this.actual + " not to have been triggered with " + jasmine.pp(expectedArgs) + " but it was triggered with " + jasmine.pp(actualArgs)
560
- ]
561
- } else {
562
- return [
563
- "Expected event " + this.actual + " to have been triggered on " + selector,
564
- "Expected event " + this.actual + " not to have been triggered on " + selector
565
- ]
566
- }
567
- }
568
-
569
- return wasTriggered && jasmine.JQuery.events.wasTriggeredWith(selector, this.actual, expectedArgs, this.env)
570
- }
571
- })
572
- this.addMatchers({
573
- toHaveBeenPreventedOn: function (selector) {
574
- this.message = function () {
575
- return [
576
- "Expected event " + this.actual + " to have been prevented on " + selector,
577
- "Expected event " + this.actual + " not to have been prevented on " + selector
578
- ]
683
+ return result
684
+ }
579
685
  }
686
+ },
580
687
 
581
- return jasmine.JQuery.events.wasPrevented(selector, this.actual)
582
- }
583
- })
584
- this.addMatchers({
585
- toHaveBeenPrevented: function () {
586
- var eventName = this.actual.eventName
587
- , selector = this.actual.selector
588
- this.message = function () {
589
- return [
590
- "Expected event " + eventName + " to have been prevented on " + selector,
591
- "Expected event " + eventName + " not to have been prevented on " + selector
592
- ]
593
- }
688
+ toHaveBeenStoppedOn: function () {
689
+ return {
690
+ compare: function (actual, selector) {
691
+ var result = { pass: jasmine.jQuery.events.wasStopped(selector, actual) }
594
692
 
595
- return jasmine.JQuery.events.wasPrevented(selector, eventName)
596
- }
597
- })
598
- this.addMatchers({
599
- toHaveBeenStoppedOn: function (selector) {
600
- this.message = function () {
601
- return [
602
- "Expected event " + this.actual + " to have been stopped on " + selector,
603
- "Expected event " + this.actual + " not to have been stopped on " + selector
604
- ]
693
+ result.message = result.pass ?
694
+ "Expected event " + actual + " not to have been stopped on " + selector :
695
+ "Expected event " + actual + " to have been stopped on " + selector
696
+
697
+ return result;
698
+ }
605
699
  }
700
+ },
606
701
 
607
- return jasmine.JQuery.events.wasStopped(selector, this.actual)
608
- }
609
- })
610
- this.addMatchers({
611
702
  toHaveBeenStopped: function () {
612
- var eventName = this.actual.eventName
613
- , selector = this.actual.selector
614
- this.message = function () {
615
- return [
616
- "Expected event " + eventName + " to have been stopped on " + selector,
617
- "Expected event " + eventName + " not to have been stopped on " + selector
618
- ]
619
- }
620
- return jasmine.JQuery.events.wasStopped(selector, eventName)
621
- }
622
- })
623
- jasmine.getEnv().addEqualityTester(function (a, b) {
624
- if(a instanceof jQuery && b instanceof jQuery) {
625
- if(a.size() != b.size()) {
626
- return jasmine.undefined
627
- }
628
- else if(a.is(b)) {
629
- return true
703
+ return {
704
+ compare: function (actual) {
705
+ var eventName = actual.eventName
706
+ , selector = actual.selector
707
+ , result = { pass: jasmine.jQuery.events.wasStopped(selector, eventName) }
708
+
709
+ result.message = result.pass ?
710
+ "Expected event " + eventName + " not to have been stopped on " + selector :
711
+ "Expected event " + eventName + " to have been stopped on " + selector
712
+
713
+ return result
714
+ }
630
715
  }
631
716
  }
717
+ })
718
+
719
+ jasmine.getEnv().addCustomEqualityTester(function(a, b) {
720
+ if (a && b) {
721
+ if (a instanceof $ || jasmine.isDomNode(a)) {
722
+ var $a = $(a)
723
+
724
+ if (b instanceof $)
725
+ return $a.length == b.length && a.is(b)
726
+
727
+ return $a.is(b);
728
+ }
729
+
730
+ if (b instanceof $ || jasmine.isDomNode(b)) {
731
+ var $b = $(b)
632
732
 
633
- return jasmine.undefined
733
+ if (a instanceof jQuery)
734
+ return a.length == $b.length && $b.is(a)
735
+
736
+ return $(b).is(a);
737
+ }
738
+ }
739
+ })
740
+
741
+ jasmine.getEnv().addCustomEqualityTester(function (a, b) {
742
+ if (a instanceof jQuery && b instanceof jQuery && a.size() == b.size())
743
+ return a.is(b)
634
744
  })
635
745
  })
636
746
 
637
747
  afterEach(function () {
638
748
  jasmine.getFixtures().cleanUp()
639
749
  jasmine.getStyleFixtures().cleanUp()
640
- jasmine.JQuery.events.cleanUp()
750
+ jasmine.jQuery.events.cleanUp()
641
751
  })
642
- }(window.jasmine, window.jQuery)
643
752
 
644
- +function (jasmine, global) { "use strict";
645
-
646
- global.readFixtures = function () {
753
+ window.readFixtures = function () {
647
754
  return jasmine.getFixtures().proxyCallTo_('read', arguments)
648
755
  }
649
756
 
650
- global.preloadFixtures = function () {
757
+ window.preloadFixtures = function () {
651
758
  jasmine.getFixtures().proxyCallTo_('preload', arguments)
652
759
  }
653
760
 
654
- global.loadFixtures = function () {
761
+ window.loadFixtures = function () {
655
762
  jasmine.getFixtures().proxyCallTo_('load', arguments)
656
763
  }
657
764
 
658
- global.appendLoadFixtures = function () {
765
+ window.appendLoadFixtures = function () {
659
766
  jasmine.getFixtures().proxyCallTo_('appendLoad', arguments)
660
767
  }
661
768
 
662
- global.setFixtures = function (html) {
769
+ window.setFixtures = function (html) {
663
770
  return jasmine.getFixtures().proxyCallTo_('set', arguments)
664
771
  }
665
772
 
666
- global.appendSetFixtures = function () {
773
+ window.appendSetFixtures = function () {
667
774
  jasmine.getFixtures().proxyCallTo_('appendSet', arguments)
668
775
  }
669
776
 
670
- global.sandbox = function (attributes) {
777
+ window.sandbox = function (attributes) {
671
778
  return jasmine.getFixtures().sandbox(attributes)
672
779
  }
673
780
 
674
- global.spyOnEvent = function (selector, eventName) {
675
- return jasmine.JQuery.events.spyOn(selector, eventName)
781
+ window.spyOnEvent = function (selector, eventName) {
782
+ return jasmine.jQuery.events.spyOn(selector, eventName)
676
783
  }
677
784
 
678
- global.preloadStyleFixtures = function () {
785
+ window.preloadStyleFixtures = function () {
679
786
  jasmine.getStyleFixtures().proxyCallTo_('preload', arguments)
680
787
  }
681
788
 
682
- global.loadStyleFixtures = function () {
789
+ window.loadStyleFixtures = function () {
683
790
  jasmine.getStyleFixtures().proxyCallTo_('load', arguments)
684
791
  }
685
792
 
686
- global.appendLoadStyleFixtures = function () {
793
+ window.appendLoadStyleFixtures = function () {
687
794
  jasmine.getStyleFixtures().proxyCallTo_('appendLoad', arguments)
688
795
  }
689
796
 
690
- global.setStyleFixtures = function (html) {
797
+ window.setStyleFixtures = function (html) {
691
798
  jasmine.getStyleFixtures().proxyCallTo_('set', arguments)
692
799
  }
693
800
 
694
- global.appendSetStyleFixtures = function (html) {
801
+ window.appendSetStyleFixtures = function (html) {
695
802
  jasmine.getStyleFixtures().proxyCallTo_('appendSet', arguments)
696
803
  }
697
804
 
698
- global.loadJSONFixtures = function () {
805
+ window.loadJSONFixtures = function () {
699
806
  return jasmine.getJSONFixtures().proxyCallTo_('load', arguments)
700
807
  }
701
808
 
702
- global.getJSONFixture = function (url) {
809
+ window.getJSONFixture = function (url) {
703
810
  return jasmine.getJSONFixtures().proxyCallTo_('read', arguments)[url]
704
811
  }
705
- }(jasmine, window);
812
+ }(window, window.jasmine, window.jQuery);
813
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jasmine-jquery-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.9
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Travis Jeffery
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-28 00:00:00.000000000 Z
11
+ date: 2014-02-05 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: