Add Grunt; jshint fixes; more tests

master
JR Boyens 12 years ago
parent 9b2852195a
commit c821f7fbc4

3
.gitignore vendored

@ -1,2 +1,3 @@
.idea/
.rvmrc
.rvmrc
node_modules

@ -0,0 +1,46 @@
module.exports = function( grunt ) {
'use strict';
//
// Grunt configuration:
//
// https://github.com/cowboy/grunt/blob/master/docs/getting_started.md
//
grunt.initConfig({
// specifying JSHint options and globals
// https://github.com/cowboy/grunt/blob/master/docs/task_lint.md#specifying-jshint-options-and-globals
jshint: {
options: {
boss: true,
browser: true,
curly: true,
eqeqeq: true,
eqnull: true,
immed: true,
latedef: true,
newcap: true,
noarg: true,
sub: true,
undef: true,
globals: {
jasmine: false,
ajaxRequests: true,
ajaxStubs: true,
module: false,
exports: true
}
},
all: ['Gruntfile.js', 'lib/*.js', 'spec/*.js']
},
shell: {
ctags: {
command: 'ctags -R lib'
}
}
});
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-shell');
grunt.registerTask('default', ['jshint']);
grunt.registerTask('ctags', 'Generate ctags', ['shell:ctags']);
};

@ -51,14 +51,16 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
clearAjaxStubs: function() {
ajaxStubs = [];
}
}
};
function extend(destination, source) {
for (var property in source) destination[property] = source[property];
for (var property in source) {
destination[property] = source[property];
}
return destination;
}
if (typeof window == "undefined" && typeof exports == "object") {
if (typeof window === "undefined" && typeof exports === "object") {
extend(exports, jasmineAjaxInterface);
} else {
extend(window, jasmineAjaxInterface);
@ -66,12 +68,12 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// Fake XHR for mocking Ajax Requests & Responses
FakeXMLHttpRequest = function() {
window.FakeXMLHttpRequest = function() {
ajaxRequests.push(this);
};
extend(FakeXMLHttpRequest.prototype, window.XMLHttpRequest);
extend(FakeXMLHttpRequest.prototype, {
extend(window.FakeXMLHttpRequest.prototype, window.XMLHttpRequest);
extend(window.FakeXMLHttpRequest.prototype, {
requestHeaders: {},
open: function() {
@ -112,7 +114,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data: function() {
var data = {};
if (typeof this.params !== 'string') return data;
if (typeof this.params !== 'string') { return data; }
var params = this.params.split('&');
for (var i = 0; i < params.length; ++i) {
@ -187,7 +189,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
installTopLevel: function() {
jasmine.Ajax.mode = 'toplevel';
jasmine.Ajax.real = window.XMLHttpRequest;
window.XMLHttpRequest = FakeXMLHttpRequest;
window.XMLHttpRequest = window.FakeXMLHttpRequest;
},
uninstallMock: function() {
@ -214,7 +216,6 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
this.responseText = options.responseText;
};
var stub = new Stub(url);
ajaxStubs.push(stub);
@ -225,7 +226,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
matchStub: function(url) {
for (var i = ajaxStubs.length - 1; i >= 0; i--) {
var stub = ajaxStubs[i];
if (stub.url == url) {
if (stub.url === url) {
return stub;
}
}

@ -0,0 +1,11 @@
{
"name": "jasmine-ajax",
"version": "2.0.0",
"private": false,
"dependencies": {
},
"devDependencies": {
"grunt": "0.4.0"
"grunt-contrib-jshint": "~0.1.1"
}
}

@ -71,5 +71,18 @@ describe("Webmock style mocking", function() {
expect(stub).toBeDefined();
});
describe("with another stub for the same url", function() {
beforeEach(function() {
jasmine.Ajax.stubRequest("http://example.com/someApi").andReturn({responseText: "no", status: 403});
});
it("should use the latest stub", function() {
var stub = jasmine.Ajax.matchStub("http://example.com/someApi");
expect(stub.status).toEqual(403);
expect(stub.responseText).toEqual('no');
});
});
});
});

Loading…
Cancel
Save