teabag 0.3.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010, 2011, 2012 Wojciech Zawistowski, Travis Jeffery
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,550 @@
1
+ //https://github.com/velesin/jasmine-jquery/commit/8903b3d4c05cc558c70b3c94adc47321920a6c11
2
+
3
+ var readFixtures = function() {
4
+ return jasmine.getFixtures().proxyCallTo_('read', arguments)
5
+ }
6
+
7
+ var preloadFixtures = function() {
8
+ jasmine.getFixtures().proxyCallTo_('preload', arguments)
9
+ }
10
+
11
+ var loadFixtures = function() {
12
+ jasmine.getFixtures().proxyCallTo_('load', arguments)
13
+ }
14
+
15
+ var appendLoadFixtures = function() {
16
+ jasmine.getFixtures().proxyCallTo_('appendLoad', arguments)
17
+ }
18
+
19
+ var setFixtures = function(html) {
20
+ jasmine.getFixtures().proxyCallTo_('set', arguments)
21
+ }
22
+
23
+ var appendSetFixtures = function() {
24
+ jasmine.getFixtures().proxyCallTo_('appendSet', arguments)
25
+ }
26
+
27
+ var sandbox = function(attributes) {
28
+ return jasmine.getFixtures().sandbox(attributes)
29
+ }
30
+
31
+ var spyOnEvent = function(selector, eventName) {
32
+ return jasmine.JQuery.events.spyOn(selector, eventName)
33
+ }
34
+
35
+ var preloadStyleFixtures = function() {
36
+ jasmine.getStyleFixtures().proxyCallTo_('preload', arguments)
37
+ }
38
+
39
+ var loadStyleFixtures = function() {
40
+ jasmine.getStyleFixtures().proxyCallTo_('load', arguments)
41
+ }
42
+
43
+ var appendLoadStyleFixtures = function() {
44
+ jasmine.getStyleFixtures().proxyCallTo_('appendLoad', arguments)
45
+ }
46
+
47
+ var setStyleFixtures = function(html) {
48
+ jasmine.getStyleFixtures().proxyCallTo_('set', arguments)
49
+ }
50
+
51
+ var appendSetStyleFixtures = function(html) {
52
+ jasmine.getStyleFixtures().proxyCallTo_('appendSet', arguments)
53
+ }
54
+
55
+ var loadJSONFixtures = function() {
56
+ return jasmine.getJSONFixtures().proxyCallTo_('load', arguments)
57
+ }
58
+
59
+ var getJSONFixture = function(url) {
60
+ return jasmine.getJSONFixtures().proxyCallTo_('read', arguments)[url]
61
+ }
62
+
63
+ jasmine.spiedEventsKey = function (selector, eventName) {
64
+ return [$(selector).selector, eventName].toString()
65
+ }
66
+
67
+ jasmine.getFixtures = function() {
68
+ return jasmine.currentFixtures_ = jasmine.currentFixtures_ || new jasmine.Fixtures()
69
+ }
70
+
71
+ jasmine.getStyleFixtures = function() {
72
+ return jasmine.currentStyleFixtures_ = jasmine.currentStyleFixtures_ || new jasmine.StyleFixtures()
73
+ }
74
+
75
+ jasmine.Fixtures = function() {
76
+ this.containerId = 'jasmine-fixtures'
77
+ this.fixturesCache_ = {}
78
+ this.fixturesPath = 'spec/javascripts/fixtures'
79
+ }
80
+
81
+ jasmine.Fixtures.prototype.set = function(html) {
82
+ this.cleanUp()
83
+ this.createContainer_(html)
84
+ }
85
+
86
+ jasmine.Fixtures.prototype.appendSet= function(html) {
87
+ this.addToContainer_(html)
88
+ }
89
+
90
+ jasmine.Fixtures.prototype.preload = function() {
91
+ this.read.apply(this, arguments)
92
+ }
93
+
94
+ jasmine.Fixtures.prototype.load = function() {
95
+ this.cleanUp()
96
+ this.createContainer_(this.read.apply(this, arguments))
97
+ }
98
+
99
+ jasmine.Fixtures.prototype.appendLoad = function() {
100
+ this.addToContainer_(this.read.apply(this, arguments))
101
+ }
102
+
103
+ jasmine.Fixtures.prototype.read = function() {
104
+ var htmlChunks = []
105
+
106
+ var fixtureUrls = arguments
107
+ for(var urlCount = fixtureUrls.length, urlIndex = 0; urlIndex < urlCount; urlIndex++) {
108
+ htmlChunks.push(this.getFixtureHtml_(fixtureUrls[urlIndex]))
109
+ }
110
+
111
+ return htmlChunks.join('')
112
+ }
113
+
114
+ jasmine.Fixtures.prototype.clearCache = function() {
115
+ this.fixturesCache_ = {}
116
+ }
117
+
118
+ jasmine.Fixtures.prototype.cleanUp = function() {
119
+ if (typeof($) == 'function') {
120
+ $('#' + this.containerId).remove()
121
+ }
122
+ }
123
+
124
+ jasmine.Fixtures.prototype.sandbox = function(attributes) {
125
+ var attributesToSet = attributes || {}
126
+ return $('<div id="sandbox" />').attr(attributesToSet)
127
+ }
128
+
129
+ jasmine.Fixtures.prototype.createContainer_ = function(html) {
130
+ var container
131
+ if(html instanceof $) {
132
+ container = $('<div id="' + this.containerId + '" />')
133
+ container.html(html)
134
+ } else {
135
+ container = '<div id="' + this.containerId + '">' + html + '</div>'
136
+ }
137
+ $('body').append(container)
138
+ }
139
+
140
+ jasmine.Fixtures.prototype.addToContainer_ = function(html){
141
+ var container = $('body').find('#'+this.containerId).append(html)
142
+ if(!container.length){
143
+ this.createContainer_(html)
144
+ }
145
+ }
146
+
147
+ jasmine.Fixtures.prototype.getFixtureHtml_ = function(url) {
148
+ if (typeof this.fixturesCache_[url] === 'undefined') {
149
+ this.loadFixtureIntoCache_(url)
150
+ }
151
+ return this.fixturesCache_[url]
152
+ }
153
+
154
+ jasmine.Fixtures.prototype.loadFixtureIntoCache_ = function(relativeUrl) {
155
+ var url = this.makeFixtureUrl_(relativeUrl)
156
+ var request = $.ajax({
157
+ type: "GET",
158
+ url: url + "?" + new Date().getTime(),
159
+ async: false
160
+ })
161
+ this.fixturesCache_[relativeUrl] = request.responseText
162
+ }
163
+
164
+ jasmine.Fixtures.prototype.makeFixtureUrl_ = function(relativeUrl){
165
+ return this.fixturesPath.match('/$') ? this.fixturesPath + relativeUrl : this.fixturesPath + '/' + relativeUrl
166
+ }
167
+
168
+ jasmine.Fixtures.prototype.proxyCallTo_ = function(methodName, passedArguments) {
169
+ return this[methodName].apply(this, passedArguments)
170
+ }
171
+
172
+
173
+ jasmine.StyleFixtures = function() {
174
+ this.fixturesCache_ = {}
175
+ this.fixturesNodes_ = []
176
+ this.fixturesPath = 'spec/javascripts/fixtures'
177
+ }
178
+
179
+ jasmine.StyleFixtures.prototype.set = function(css) {
180
+ this.cleanUp()
181
+ this.createStyle_(css)
182
+ }
183
+
184
+ jasmine.StyleFixtures.prototype.appendSet = function(css) {
185
+ this.createStyle_(css)
186
+ }
187
+
188
+ jasmine.StyleFixtures.prototype.preload = function() {
189
+ this.read_.apply(this, arguments)
190
+ }
191
+
192
+ jasmine.StyleFixtures.prototype.load = function() {
193
+ this.cleanUp()
194
+ this.createStyle_(this.read_.apply(this, arguments))
195
+ }
196
+
197
+ jasmine.StyleFixtures.prototype.appendLoad = function() {
198
+ this.createStyle_(this.read_.apply(this, arguments))
199
+ }
200
+
201
+ jasmine.StyleFixtures.prototype.cleanUp = function() {
202
+ while(this.fixturesNodes_.length) {
203
+ this.fixturesNodes_.pop().remove()
204
+ }
205
+ }
206
+
207
+ jasmine.StyleFixtures.prototype.createStyle_ = function(html) {
208
+ var styleText = $('<div></div>').html(html).text(),
209
+ style = $('<style>' + styleText + '</style>')
210
+
211
+ this.fixturesNodes_.push(style)
212
+
213
+ $('head').append(style)
214
+ }
215
+
216
+ jasmine.StyleFixtures.prototype.clearCache = jasmine.Fixtures.prototype.clearCache
217
+
218
+ jasmine.StyleFixtures.prototype.read_ = jasmine.Fixtures.prototype.read
219
+
220
+ jasmine.StyleFixtures.prototype.getFixtureHtml_ = jasmine.Fixtures.prototype.getFixtureHtml_
221
+
222
+ jasmine.StyleFixtures.prototype.loadFixtureIntoCache_ = jasmine.Fixtures.prototype.loadFixtureIntoCache_
223
+
224
+ jasmine.StyleFixtures.prototype.makeFixtureUrl_ = jasmine.Fixtures.prototype.makeFixtureUrl_
225
+
226
+ jasmine.StyleFixtures.prototype.proxyCallTo_ = jasmine.Fixtures.prototype.proxyCallTo_
227
+
228
+ jasmine.getJSONFixtures = function() {
229
+ return jasmine.currentJSONFixtures_ = jasmine.currentJSONFixtures_ || new jasmine.JSONFixtures()
230
+ }
231
+
232
+ jasmine.JSONFixtures = function() {
233
+ this.fixturesCache_ = {}
234
+ this.fixturesPath = 'spec/javascripts/fixtures/json'
235
+ }
236
+
237
+ jasmine.JSONFixtures.prototype.load = function() {
238
+ this.read.apply(this, arguments)
239
+ return this.fixturesCache_
240
+ }
241
+
242
+ jasmine.JSONFixtures.prototype.read = function() {
243
+ var fixtureUrls = arguments
244
+ for(var urlCount = fixtureUrls.length, urlIndex = 0; urlIndex < urlCount; urlIndex++) {
245
+ this.getFixtureData_(fixtureUrls[urlIndex])
246
+ }
247
+ return this.fixturesCache_
248
+ }
249
+
250
+ jasmine.JSONFixtures.prototype.clearCache = function() {
251
+ this.fixturesCache_ = {}
252
+ }
253
+
254
+ jasmine.JSONFixtures.prototype.getFixtureData_ = function(url) {
255
+ this.loadFixtureIntoCache_(url)
256
+ return this.fixturesCache_[url]
257
+ }
258
+
259
+ jasmine.JSONFixtures.prototype.loadFixtureIntoCache_ = function(relativeUrl) {
260
+ var self = this
261
+ var url = this.fixturesPath.match('/$') ? this.fixturesPath + relativeUrl : this.fixturesPath + '/' + relativeUrl
262
+ $.ajax({
263
+ async: false, // must be synchronous to guarantee that no tests are run before fixture is loaded
264
+ cache: false,
265
+ dataType: 'json',
266
+ url: url,
267
+ success: function(data) {
268
+ self.fixturesCache_[relativeUrl] = data
269
+ },
270
+ error: function(jqXHR, status, errorThrown) {
271
+ throw Error('JSONFixture could not be loaded: ' + url + ' (status: ' + status + ', message: ' + errorThrown.message + ')')
272
+ }
273
+ })
274
+ }
275
+
276
+ jasmine.JSONFixtures.prototype.proxyCallTo_ = function(methodName, passedArguments) {
277
+ return this[methodName].apply(this, passedArguments)
278
+ }
279
+
280
+ jasmine.JQuery = function() {}
281
+
282
+ jasmine.JQuery.browserTagCaseIndependentHtml = function(html) {
283
+ return $('<div/>').append(html).html()
284
+ }
285
+
286
+ jasmine.JQuery.elementToString = function(element) {
287
+ var domEl = $(element).get(0)
288
+ if (domEl == undefined || domEl.cloneNode)
289
+ return $('<div />').append($(element).clone()).html()
290
+ else
291
+ return element.toString()
292
+ }
293
+
294
+ jasmine.JQuery.matchersClass = {}
295
+
296
+ !function(namespace) {
297
+ var data = {
298
+ spiedEvents: {},
299
+ handlers: []
300
+ }
301
+
302
+ namespace.events = {
303
+ spyOn: function(selector, eventName) {
304
+ var handler = function(e) {
305
+ data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)] = e
306
+ }
307
+ $(selector).bind(eventName, handler)
308
+ data.handlers.push(handler)
309
+ return {
310
+ selector: selector,
311
+ eventName: eventName,
312
+ handler: handler,
313
+ reset: function(){
314
+ delete data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)]
315
+ }
316
+ }
317
+ },
318
+
319
+ wasTriggered: function(selector, eventName) {
320
+ return !!(data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)])
321
+ },
322
+
323
+ wasPrevented: function(selector, eventName) {
324
+ return data.spiedEvents[jasmine.spiedEventsKey(selector, eventName)].isDefaultPrevented()
325
+ },
326
+
327
+ cleanUp: function() {
328
+ data.spiedEvents = {}
329
+ data.handlers = []
330
+ }
331
+ }
332
+ }(jasmine.JQuery)
333
+
334
+ !function(){
335
+ var jQueryMatchers = {
336
+ toHaveClass: function(className) {
337
+ return this.actual.hasClass(className)
338
+ },
339
+
340
+ toHaveCss: function(css){
341
+ for (var prop in css){
342
+ if (this.actual.css(prop) !== css[prop]) return false
343
+ }
344
+ return true
345
+ },
346
+
347
+ toBeVisible: function() {
348
+ return this.actual.is(':visible')
349
+ },
350
+
351
+ toBeHidden: function() {
352
+ return this.actual.is(':hidden')
353
+ },
354
+
355
+ toBeSelected: function() {
356
+ return this.actual.is(':selected')
357
+ },
358
+
359
+ toBeChecked: function() {
360
+ return this.actual.is(':checked')
361
+ },
362
+
363
+ toBeEmpty: function() {
364
+ return this.actual.is(':empty')
365
+ },
366
+
367
+ toExist: function() {
368
+ return $(document).find(this.actual).length
369
+ },
370
+
371
+ toHaveAttr: function(attributeName, expectedAttributeValue) {
372
+ return hasProperty(this.actual.attr(attributeName), expectedAttributeValue)
373
+ },
374
+
375
+ toHaveProp: function(propertyName, expectedPropertyValue) {
376
+ return hasProperty(this.actual.prop(propertyName), expectedPropertyValue)
377
+ },
378
+
379
+ toHaveId: function(id) {
380
+ return this.actual.attr('id') == id
381
+ },
382
+
383
+ toHaveHtml: function(html) {
384
+ return this.actual.html() == jasmine.JQuery.browserTagCaseIndependentHtml(html)
385
+ },
386
+
387
+ toContainHtml: function(html){
388
+ var actualHtml = this.actual.html()
389
+ var expectedHtml = jasmine.JQuery.browserTagCaseIndependentHtml(html)
390
+ return (actualHtml.indexOf(expectedHtml) >= 0)
391
+ },
392
+
393
+ toHaveText: function(text) {
394
+ var trimmedText = $.trim(this.actual.text())
395
+ if (text && $.isFunction(text.test)) {
396
+ return text.test(trimmedText)
397
+ } else {
398
+ return trimmedText == text
399
+ }
400
+ },
401
+
402
+ toHaveValue: function(value) {
403
+ return this.actual.val() == value
404
+ },
405
+
406
+ toHaveData: function(key, expectedValue) {
407
+ return hasProperty(this.actual.data(key), expectedValue)
408
+ },
409
+
410
+ toBe: function(selector) {
411
+ return this.actual.is(selector)
412
+ },
413
+
414
+ toContain: function(selector) {
415
+ return this.actual.find(selector).length
416
+ },
417
+
418
+ toBeDisabled: function(selector){
419
+ return this.actual.is(':disabled')
420
+ },
421
+
422
+ toBeFocused: function(selector) {
423
+ return this.actual.is(':focus')
424
+ },
425
+
426
+ toHandle: function(event) {
427
+
428
+ var events = $._data(this.actual.get(0), "events")
429
+
430
+ if(!events || !event || typeof event !== "string") {
431
+ return false
432
+ }
433
+
434
+ var namespaces = event.split(".")
435
+ var eventType = namespaces.shift()
436
+ var sortedNamespaces = namespaces.slice(0).sort()
437
+ var namespaceRegExp = new RegExp("(^|\\.)" + sortedNamespaces.join("\\.(?:.*\\.)?") + "(\\.|$)")
438
+
439
+ if(events[eventType] && namespaces.length) {
440
+ for(var i = 0; i < events[eventType].length; i++) {
441
+ var namespace = events[eventType][i].namespace
442
+ if(namespaceRegExp.test(namespace)) {
443
+ return true
444
+ }
445
+ }
446
+ } else {
447
+ return events[eventType] && events[eventType].length > 0
448
+ }
449
+ },
450
+
451
+ // tests the existence of a specific event binding + handler
452
+ toHandleWith: function(eventName, eventHandler) {
453
+ var stack = $._data(this.actual.get(0), "events")[eventName]
454
+ for (var i = 0; i < stack.length; i++) {
455
+ if (stack[i].handler == eventHandler) return true
456
+ }
457
+ return false
458
+ }
459
+ }
460
+
461
+ var hasProperty = function(actualValue, expectedValue) {
462
+ if (expectedValue === undefined) return actualValue !== undefined
463
+ return actualValue == expectedValue
464
+ }
465
+
466
+ var bindMatcher = function(methodName) {
467
+ var builtInMatcher = jasmine.Matchers.prototype[methodName]
468
+
469
+ jasmine.JQuery.matchersClass[methodName] = function() {
470
+ if (this.actual
471
+ && (this.actual instanceof $
472
+ || jasmine.isDomNode(this.actual))) {
473
+ this.actual = $(this.actual)
474
+ var result = jQueryMatchers[methodName].apply(this, arguments)
475
+ var element
476
+ if (this.actual.get && (element = this.actual.get()[0]) && !$.isWindow(element) && element.tagName !== "HTML")
477
+ this.actual = jasmine.JQuery.elementToString(this.actual)
478
+ return result
479
+ }
480
+
481
+ if (builtInMatcher) {
482
+ return builtInMatcher.apply(this, arguments)
483
+ }
484
+
485
+ return false
486
+ }
487
+ }
488
+
489
+ for(var methodName in jQueryMatchers) {
490
+ bindMatcher(methodName)
491
+ }
492
+ }()
493
+
494
+ beforeEach(function() {
495
+ this.addMatchers(jasmine.JQuery.matchersClass)
496
+ this.addMatchers({
497
+ toHaveBeenTriggeredOn: function(selector) {
498
+ this.message = function() {
499
+ return [
500
+ "Expected event " + this.actual + " to have been triggered on " + selector,
501
+ "Expected event " + this.actual + " not to have been triggered on " + selector
502
+ ]
503
+ }
504
+ return jasmine.JQuery.events.wasTriggered(selector, this.actual)
505
+ }
506
+ })
507
+ this.addMatchers({
508
+ toHaveBeenTriggered: function(){
509
+ var eventName = this.actual.eventName,
510
+ selector = this.actual.selector
511
+ this.message = function() {
512
+ return [
513
+ "Expected event " + eventName + " to have been triggered on " + selector,
514
+ "Expected event " + eventName + " not to have been triggered on " + selector
515
+ ]
516
+ }
517
+ return jasmine.JQuery.events.wasTriggered(selector, eventName)
518
+ }
519
+ })
520
+ this.addMatchers({
521
+ toHaveBeenPreventedOn: function(selector) {
522
+ this.message = function() {
523
+ return [
524
+ "Expected event " + this.actual + " to have been prevented on " + selector,
525
+ "Expected event " + this.actual + " not to have been prevented on " + selector
526
+ ]
527
+ }
528
+ return jasmine.JQuery.events.wasPrevented(selector, this.actual)
529
+ }
530
+ })
531
+ this.addMatchers({
532
+ toHaveBeenPrevented: function() {
533
+ var eventName = this.actual.eventName,
534
+ selector = this.actual.selector
535
+ this.message = function() {
536
+ return [
537
+ "Expected event " + eventName + " to have been prevented on " + selector,
538
+ "Expected event " + eventName + " not to have been prevented on " + selector
539
+ ]
540
+ }
541
+ return jasmine.JQuery.events.wasPrevented(selector, eventName)
542
+ }
543
+ })
544
+ })
545
+
546
+ afterEach(function() {
547
+ jasmine.getFixtures().cleanUp()
548
+ jasmine.getStyleFixtures().cleanUp()
549
+ jasmine.JQuery.events.cleanUp()
550
+ })