pull jquery and prototype mocks into named functions

This commit is contained in:
Hunter Gillane 2011-08-07 14:20:37 -06:00
parent 9536fe9d02
commit 26e475dfb2
4 changed files with 49 additions and 39 deletions

6
.pairs Normal file
View File

@ -0,0 +1,6 @@
pairs:
hg: Hunter Gillane
email:
prefix: pair
domain: pivotallabs.com

View File

@ -1,35 +1,35 @@
/*
Jasmine-Ajax : a set of helpers for testing AJAX requests under the Jasmine
BDD framework for JavaScript.
Jasmine-Ajax : a set of helpers for testing AJAX requests under the Jasmine
BDD framework for JavaScript.
Supports both Prototype.js and jQuery.
Supports both Prototype.js and jQuery.
http://github.com/pivotal/jasmine-ajax
http://github.com/pivotal/jasmine-ajax
Jasmine Home page: http://pivotal.github.com/jasmine
Jasmine Home page: http://pivotal.github.com/jasmine
Copyright (c) 2008-2010 Pivotal Labs
Copyright (c) 2008-2010 Pivotal Labs
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
*/
// Jasmine-Ajax interface
var ajaxRequests = [];
@ -151,11 +151,7 @@ jasmine.Ajax = {
installJquery: function() {
jasmine.Ajax.mode = 'jQuery';
jasmine.Ajax.real = jQuery.ajaxSettings.xhr;
jQuery.ajaxSettings.xhr = function() {
var newXhr = new FakeXMLHttpRequest();
ajaxRequests.push(newXhr);
return newXhr;
}
jQuery.ajaxSettings.xhr = jasmine.Ajax.jQueryMock;
},
@ -163,9 +159,7 @@ jasmine.Ajax = {
jasmine.Ajax.mode = 'Prototype';
jasmine.Ajax.real = Ajax.getTransport;
Ajax.getTransport = function() {
return new FakeXMLHttpRequest();
};
Ajax.getTransport = jasmine.Ajax.prototypeMock;
},
uninstallMock: function() {
@ -184,6 +178,16 @@ jasmine.Ajax = {
jasmine.Ajax.real = null;
},
jQueryMock: function() {
var newXhr = new FakeXMLHttpRequest();
ajaxRequests.push(newXhr);
return newXhr;
},
prototypeMock: function() {
return new FakeXMLHttpRequest();
},
installed: false,
mode: null
}

View File

@ -36,10 +36,10 @@ describe("FakeXMLHttpRequest", function() {
});
});
it("can be extended", function(){
FakeXMLHttpRequest.prototype.foo = function(){
return "foo";
}
expect(new FakeXMLHttpRequest().foo()).toEqual("foo");
});
it("can be extended", function(){
FakeXMLHttpRequest.prototype.foo = function(){
return "foo";
}
expect(new FakeXMLHttpRequest().foo()).toEqual("foo");
});
});

View File

@ -39,7 +39,7 @@ describe("jasmine.Ajax", function() {
it("installs the mock", function() {
withoutPrototype(function() {
jasmine.Ajax.installMock();
expect(jQuery.ajaxSettings.xhr).toBe(FakeXMLHttpRequest);
expect(jQuery.ajaxSettings.xhr).toBe(jasmine.Ajax.jQueryMock);
});
});
@ -63,7 +63,7 @@ describe("jasmine.Ajax", function() {
it("installs the mock", function() {
withoutJquery(function() {
jasmine.Ajax.installMock();
expect(Ajax.getTransport).toBe(FakeXMLHttpRequest);
expect(Ajax.getTransport).toBe(jasmine.Ajax.prototypeMock);
});
});