browse-everything 1.1.2 → 1.2.0

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