qunit_for_rails 0.0.6 → 0.0.7

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.
data/Gemfile CHANGED
@@ -5,4 +5,4 @@ source "http://rubygems.org"
5
5
  # gem 'ruby-debug19'
6
6
 
7
7
  #gem "rails", "3.0.10"
8
- gem "haml", ">= 3.1.2"
8
+ gem "haml", "3.1.2"
data/Gemfile.lock CHANGED
@@ -1,10 +1,10 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- haml (3.1.4)
4
+ haml (3.1.2)
5
5
 
6
6
  PLATFORMS
7
7
  ruby
8
8
 
9
9
  DEPENDENCIES
10
- haml (>= 3.1.2)
10
+ haml (= 3.1.2)
@@ -7,6 +7,7 @@
7
7
  %script{:type => "text/javascript", :src => "#{root_url}/javascripts/qunit_for_rails/qunit.js"}
8
8
  %script{:type => "text/javascript", :src => "#{root_url}/javascripts/qunit_for_rails/qunit.test_loader.js"}
9
9
  %script{:type => "text/javascript", :src => "#{root_url}/javascripts/qunit_for_rails/qunit_for_rails.js"}
10
+ %script{:type => "text/javascript", :src => "#{root_url}/javascripts/qunit_for_rails/jquery.mockjax.js"}
10
11
 
11
12
  :javascript
12
13
  var QFR = {};
@@ -1,3 +1,3 @@
1
1
  module QunitForRails
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -0,0 +1,409 @@
1
+ /*!
2
+ * MockJax - jQuery Plugin to Mock Ajax requests
3
+ *
4
+ * Version: 1.5.0pre
5
+ * Released:
6
+ * Home: http://github.com/appendto/jquery-mockjax
7
+ * Author: Jonathan Sharp (http://jdsharp.com)
8
+ * License: MIT,GPL
9
+ *
10
+ * Copyright (c) 2011 appendTo LLC.
11
+ * Dual licensed under the MIT or GPL licenses.
12
+ * http://appendto.com/open-source-licenses
13
+ */
14
+ (function($) {
15
+ var _ajax = $.ajax,
16
+ mockHandlers = [];
17
+
18
+ function parseXML(xml) {
19
+ if ( window['DOMParser'] == undefined && window.ActiveXObject ) {
20
+ DOMParser = function() { };
21
+ DOMParser.prototype.parseFromString = function( xmlString ) {
22
+ var doc = new ActiveXObject('Microsoft.XMLDOM');
23
+ doc.async = 'false';
24
+ doc.loadXML( xmlString );
25
+ return doc;
26
+ };
27
+ }
28
+
29
+ try {
30
+ var xmlDoc = ( new DOMParser() ).parseFromString( xml, 'text/xml' );
31
+ if ( $.isXMLDoc( xmlDoc ) ) {
32
+ var err = $('parsererror', xmlDoc);
33
+ if ( err.length == 1 ) {
34
+ throw('Error: ' + $(xmlDoc).text() );
35
+ }
36
+ } else {
37
+ throw('Unable to parse XML');
38
+ }
39
+ } catch( e ) {
40
+ var msg = ( e.name == undefined ? e : e.name + ': ' + e.message );
41
+ $(document).trigger('xmlParseError', [ msg ]);
42
+ return undefined;
43
+ }
44
+ return xmlDoc;
45
+ }
46
+
47
+ $.extend({
48
+ ajax: function(url, origSettings) {
49
+ // If url is an object, simulate pre-1.5 signature
50
+ if ( typeof url === "object" ) {
51
+ origSettings = url;
52
+ url = undefined;
53
+ } else {
54
+ // work around to support 1.5 signature
55
+ origSettings.url = url;
56
+ }
57
+ var s = jQuery.extend(true, {}, jQuery.ajaxSettings, origSettings),
58
+ mock = false;
59
+ // Iterate over our mock handlers (in registration order) until we find
60
+ // one that is willing to intercept the request
61
+ $.each(mockHandlers, function(k, v) {
62
+ if ( !mockHandlers[k] ) {
63
+ return;
64
+ }
65
+ var m = null;
66
+ // If the mock was registered with a function, let the function decide if we
67
+ // want to mock this request
68
+ if ( $.isFunction(mockHandlers[k]) ) {
69
+ m = mockHandlers[k](s);
70
+ } else {
71
+ m = mockHandlers[k];
72
+ // Inspect the URL of the request and check if the mock handler's url
73
+ // matches the url for this ajax request
74
+ if ( $.isFunction(m.url.test) ) {
75
+ // The user provided a regex for the url, test it
76
+ if ( !m.url.test( s.url ) ) {
77
+ m = null;
78
+ }
79
+ } else {
80
+ // Look for a simple wildcard '*' or a direct URL match
81
+ var star = m.url.indexOf('*');
82
+ if (m.url !== s.url && star === -1 || !new RegExp(m.url.replace(/[-[\]{}()+?.,\\^$|#\s]/g, "\\$&").replace('*', '.+')).test(s.url)) {
83
+ m = null;
84
+ }
85
+ }
86
+ if ( m ) {
87
+ // Inspect the data submitted in the request (either POST body or GET query string)
88
+ if ( m.data && s.data ) {
89
+ var identical = false;
90
+ // Deep inspect the identity of the objects
91
+ (function ident(mock, live) {
92
+ // Test for situations where the data is a querystring (not an object)
93
+ if (typeof live === 'string') {
94
+ // Querystring may be a regex
95
+ identical = $.isFunction( mock.test ) ? mock.test(live) : mock == live;
96
+ return identical;
97
+ }
98
+ $.each(mock, function(k, v) {
99
+ if ( live[k] === undefined ) {
100
+ identical = false;
101
+ return false;
102
+ } else {
103
+ identical = true;
104
+ if ( typeof live[k] == 'object' ) {
105
+ return ident(mock[k], live[k]);
106
+ } else {
107
+ if ( $.isFunction( mock[k].test ) ) {
108
+ identical = mock[k].test(live[k]);
109
+ } else {
110
+ identical = ( mock[k] == live[k] );
111
+ }
112
+ return identical;
113
+ }
114
+ }
115
+ });
116
+ })(m.data, s.data);
117
+ // They're not identical, do not mock this request
118
+ if ( identical == false ) {
119
+ m = null;
120
+ }
121
+ }
122
+ // Inspect the request type
123
+ if ( m && m.type && m.type.toLowerCase() != s.type.toLowerCase() ) {
124
+ // The request type doesn't match (GET vs. POST)
125
+ m = null;
126
+ }
127
+ }
128
+ }
129
+ if ( m ) {
130
+ mock = true;
131
+
132
+ // Handle console logging
133
+ var c = $.extend({}, $.mockjaxSettings, m);
134
+ if ( c.log && $.isFunction(c.log) ) {
135
+ c.log('MOCK ' + s.type.toUpperCase() + ': ' + s.url, $.extend({}, s));
136
+ }
137
+
138
+ var jsre = /=\?(&|$)/, jsc = (new Date()).getTime();
139
+
140
+ // Handle JSONP Parameter Callbacks, we need to replicate some of the jQuery core here
141
+ // because there isn't an easy hook for the cross domain script tag of jsonp
142
+ if ( s.dataType === "jsonp" ) {
143
+ if ( s.type.toUpperCase() === "GET" ) {
144
+ if ( !jsre.test( s.url ) ) {
145
+ s.url += (rquery.test( s.url ) ? "&" : "?") + (s.jsonp || "callback") + "=?";
146
+ }
147
+ } else if ( !s.data || !jsre.test(s.data) ) {
148
+ s.data = (s.data ? s.data + "&" : "") + (s.jsonp || "callback") + "=?";
149
+ }
150
+ s.dataType = "json";
151
+ }
152
+
153
+ // Build temporary JSONP function
154
+ if ( s.dataType === "json" && (s.data && jsre.test(s.data) || jsre.test(s.url)) ) {
155
+ jsonp = s.jsonpCallback || ("jsonp" + jsc++);
156
+
157
+ // Replace the =? sequence both in the query string and the data
158
+ if ( s.data ) {
159
+ s.data = (s.data + "").replace(jsre, "=" + jsonp + "$1");
160
+ }
161
+
162
+ s.url = s.url.replace(jsre, "=" + jsonp + "$1");
163
+
164
+ // We need to make sure
165
+ // that a JSONP style response is executed properly
166
+ s.dataType = "script";
167
+
168
+ // Handle JSONP-style loading
169
+ window[ jsonp ] = window[ jsonp ] || function( tmp ) {
170
+ data = tmp;
171
+ success();
172
+ complete();
173
+ // Garbage collect
174
+ window[ jsonp ] = undefined;
175
+
176
+ try {
177
+ delete window[ jsonp ];
178
+ } catch(e) {}
179
+
180
+ if ( head ) {
181
+ head.removeChild( script );
182
+ }
183
+ };
184
+ }
185
+
186
+ var rurl = /^(\w+:)?\/\/([^\/?#]+)/,
187
+ parts = rurl.exec( s.url ),
188
+ remote = parts && (parts[1] && parts[1] !== location.protocol || parts[2] !== location.host);
189
+
190
+ // Test if we are going to create a script tag (if so, intercept & mock)
191
+ if ( s.dataType === "script" && s.type.toUpperCase() === "GET" && remote ) {
192
+ // Synthesize the mock request for adding a script tag
193
+ var callbackContext = origSettings && origSettings.context || s;
194
+
195
+ function success() {
196
+ // If a local callback was specified, fire it and pass it the data
197
+ if ( s.success ) {
198
+ s.success.call( callbackContext, ( m.response ? m.response.toString() : m.responseText || ''), status, {} );
199
+ }
200
+
201
+ // Fire the global callback
202
+ if ( s.global ) {
203
+ trigger( "ajaxSuccess", [{}, s] );
204
+ }
205
+ }
206
+
207
+ function complete() {
208
+ // Process result
209
+ if ( s.complete ) {
210
+ s.complete.call( callbackContext, {} , status );
211
+ }
212
+
213
+ // The request was completed
214
+ if ( s.global ) {
215
+ trigger( "ajaxComplete", [{}, s] );
216
+ }
217
+
218
+ // Handle the global AJAX counter
219
+ if ( s.global && ! --jQuery.active ) {
220
+ jQuery.event.trigger( "ajaxStop" );
221
+ }
222
+ }
223
+
224
+ function trigger(type, args) {
225
+ (s.context ? jQuery(s.context) : jQuery.event).trigger(type, args);
226
+ }
227
+
228
+ if ( m.response && $.isFunction(m.response) ) {
229
+ m.response(origSettings);
230
+ } else {
231
+ $.globalEval(m.responseText);
232
+ }
233
+ success();
234
+ complete();
235
+ return false;
236
+ }
237
+
238
+ m.data = s.data;
239
+ m.cache = s.cache;
240
+ m.timeout = s.timeout;
241
+ m.global = s.global;
242
+
243
+ mock = _ajax.call($, $.extend(true, {}, origSettings, {
244
+ // Mock the XHR object
245
+ xhr: function() {
246
+ // Extend with our default mockjax settings
247
+ m = $.extend({}, $.mockjaxSettings, m);
248
+
249
+ if (typeof m.headers === 'undefined') {
250
+ m.headers = {};
251
+ }
252
+ if ( m.contentType ) {
253
+ m.headers['content-type'] = m.contentType;
254
+ }
255
+
256
+ // Return our mock xhr object
257
+ return {
258
+ status: m.status,
259
+ readyState: 1,
260
+ open: function() { },
261
+ send: function() {
262
+
263
+ mockHandlers[k].fired = true;
264
+
265
+ // This is a substitute for < 1.4 which lacks $.proxy
266
+ var process = (function(that) {
267
+ return function() {
268
+ return (function() {
269
+ // The request has returned
270
+ this.status = m.status;
271
+ this.readyState = 4;
272
+
273
+ // We have an executable function, call it to give
274
+ // the mock handler a chance to update it's data
275
+ if ( $.isFunction(m.response) ) {
276
+ m.response(origSettings);
277
+ }
278
+ // Copy over our mock to our xhr object before passing control back to
279
+ // jQuery's onreadystatechange callback
280
+ if ( s.dataType == 'json' && ( typeof m.responseText == 'object' ) ) {
281
+ this.responseText = JSON.stringify(m.responseText);
282
+ } else if ( s.dataType == 'xml' ) {
283
+ if ( typeof m.responseXML == 'string' ) {
284
+ this.responseXML = parseXML(m.responseXML);
285
+ } else {
286
+ this.responseXML = m.responseXML;
287
+ }
288
+ } else {
289
+ this.responseText = m.responseText;
290
+ }
291
+ if( typeof m.status == 'number' || typeof m.status == 'string' ) {
292
+ this.status = m.status;
293
+ }
294
+ // jQuery < 1.4 doesn't have onreadystate change for xhr
295
+ if ( $.isFunction(this.onreadystatechange) ) {
296
+ this.onreadystatechange( m.isTimeout ? 'timeout' : undefined );
297
+ }
298
+ }).apply(that);
299
+ };
300
+ })(this);
301
+
302
+ if ( m.proxy ) {
303
+ // We're proxying this request and loading in an external file instead
304
+ _ajax({
305
+ global: false,
306
+ url: m.proxy,
307
+ type: m.proxyType,
308
+ data: m.data,
309
+ dataType: s.dataType,
310
+ complete: function(xhr, txt) {
311
+ m.responseXML = xhr.responseXML;
312
+ m.responseText = xhr.responseText;
313
+ m.status = xhr.status;
314
+ this.responseTimer = setTimeout(process, m.responseTime || 0);
315
+ }
316
+ });
317
+ } else {
318
+ // type == 'POST' || 'GET' || 'DELETE'
319
+ if ( s.async === false ) {
320
+ // TODO: Blocking delay
321
+ process();
322
+ } else {
323
+ this.responseTimer = setTimeout(process, m.responseTime || 50);
324
+ }
325
+ }
326
+ },
327
+ abort: function() {
328
+ clearTimeout(this.responseTimer);
329
+ },
330
+ setRequestHeader: function(header, value) {
331
+ m.headers[header] = value;
332
+ },
333
+ getResponseHeader: function(header) {
334
+ // 'Last-modified', 'Etag', 'content-type' are all checked by jQuery
335
+ if ( m.headers && m.headers[header] ) {
336
+ // Return arbitrary headers
337
+ return m.headers[header];
338
+ } else if ( header.toLowerCase() == 'last-modified' ) {
339
+ return m.lastModified || (new Date()).toString();
340
+ } else if ( header.toLowerCase() == 'etag' ) {
341
+ return m.etag || '';
342
+ } else if ( header.toLowerCase() == 'content-type' ) {
343
+ return m.contentType || 'text/plain';
344
+ }
345
+ },
346
+ getAllResponseHeaders: function() {
347
+ var headers = '';
348
+ $.each(m.headers, function(k, v) {
349
+ headers += k + ': ' + v + "\n";
350
+ });
351
+ return headers;
352
+ }
353
+ };
354
+ }
355
+ }));
356
+ return false;
357
+ }
358
+ });
359
+ // We don't have a mock request, trigger a normal request
360
+ if ( !mock ) {
361
+ return _ajax.apply($, arguments);
362
+ } else {
363
+ return mock;
364
+ }
365
+ }
366
+ });
367
+
368
+ $.mockjaxSettings = {
369
+ //url: null,
370
+ //type: 'GET',
371
+ log: function(msg) {
372
+ window['console'] && window.console.log && window.console.log(msg);
373
+ },
374
+ status: 200,
375
+ responseTime: 500,
376
+ isTimeout: false,
377
+ contentType: 'text/plain',
378
+ response: '',
379
+ responseText: '',
380
+ responseXML: '',
381
+ proxy: '',
382
+ proxyType: 'GET',
383
+
384
+ lastModified: null,
385
+ etag: '',
386
+ headers: {
387
+ etag: 'IJF@H#@923uf8023hFO@I#H#',
388
+ 'content-type' : 'text/plain'
389
+ }
390
+ };
391
+
392
+ $.mockjax = function(settings) {
393
+ var i = mockHandlers.length;
394
+ mockHandlers[i] = settings;
395
+ return i;
396
+ };
397
+ $.mockjaxClear = function(i) {
398
+ if ( arguments.length == 1 ) {
399
+ mockHandlers[i] = null;
400
+ } else {
401
+ mockHandlers = [];
402
+ }
403
+ };
404
+ $.mockjax.handler = function(i) {
405
+ if ( arguments.length == 1 ) {
406
+ return mockHandlers[i];
407
+ }
408
+ };
409
+ })(jQuery);
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qunit_for_rails
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 6
10
- version: 0.0.6
9
+ - 7
10
+ version: 0.0.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - Michael Krisher
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-12-15 00:00:00 Z
19
+ date: 2011-12-16 00:00:00 Z
20
20
  dependencies: []
21
21
 
22
22
  description: Helper to integrate QUnit JavaScript testing into any Rails app
@@ -51,6 +51,7 @@ files:
51
51
  - public/javascripts/qunit_for_rails/index.js
52
52
  - public/javascripts/qunit_for_rails/inject.js
53
53
  - public/javascripts/qunit_for_rails/jquery-1.6.4.min.js
54
+ - public/javascripts/qunit_for_rails/jquery.mockjax.js
54
55
  - public/javascripts/qunit_for_rails/qunit.js
55
56
  - public/javascripts/qunit_for_rails/qunit.page_load.js
56
57
  - public/javascripts/qunit_for_rails/qunit.test_loader.js
@@ -131,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
132
  requirements: []
132
133
 
133
134
  rubyforge_project: qunit_for_rails
134
- rubygems_version: 1.8.11
135
+ rubygems_version: 1.7.2
135
136
  signing_key:
136
137
  specification_version: 3
137
138
  summary: ""