Permalink
Browse files

fix specs to work with rdy's switch to stock XHR

many fixture loading specs were failing due to the fact that they were still spying on $.ajax, which was no longer used.

In support of this fix, I separated out the actual request from the url building step, since that also had test coverage in need of fixing.
  • Loading branch information...
1 parent 4ff89ba commit c2f7dc7a72cd099ac09b0b48a96c51e112f7e2af @coreyti committed May 8, 2012
Showing with 20 additions and 11 deletions.
  1. +9 −1 lib/jasmine-jquery.js
  2. +11 −10 spec/suites/jasmine-jquery-spec.js
View
@@ -90,10 +90,18 @@ jasmine.Fixtures.prototype.getFixtureHtml_ = function(url) {
jasmine.Fixtures.prototype.loadFixtureIntoCache_ = function(relativeUrl) {
var url = this.fixturesPath.match('/$') ? this.fixturesPath + relativeUrl : this.fixturesPath + '/' + relativeUrl;
+ this.fixturesCache_[relativeUrl] = this.retrieveRemoteFile_(url);
+};
+
+jasmine.Fixtures.prototype.retrieveRemoteFile_ = function(url) {
var request = new XMLHttpRequest();
request.open("GET", url + "?" + new Date().getTime(), false);
request.send(null);
- this.fixturesCache_[relativeUrl] = request.responseText;
+
+ if(request.status >= 400) {
+ throw Error('Fixture could not be loaded: ' + url + ' (status: ' + status + ', message: ' + errorThrown.message + ')');
+ }
+ return request.responseText;
};
jasmine.Fixtures.prototype.proxyCallTo_ = function(methodName, passedArguments) {
@@ -11,8 +11,9 @@ describe("jasmine.Fixtures", function() {
beforeEach(function() {
jasmine.getFixtures().clearCache();
- spyOn($, 'ajax').andCallFake(function(options) {
- options.success(ajaxData);
+
+ spyOn(jasmine.Fixtures.prototype, 'retrieveRemoteFile_').andCallFake(function(url) {
+ return ajaxData;
});
});
@@ -32,18 +33,18 @@ describe("jasmine.Fixtures", function() {
jasmine.getFixtures().read(fixtureUrl);
jasmine.getFixtures().clearCache();
jasmine.getFixtures().read(fixtureUrl);
- expect($.ajax.callCount).toEqual(2);
+ expect(jasmine.Fixtures.prototype.retrieveRemoteFile_.callCount).toEqual(2);
});
});
it("first-time read should go through AJAX", function() {
jasmine.getFixtures().read(fixtureUrl);
- expect($.ajax.callCount).toEqual(1);
+ expect(jasmine.Fixtures.prototype.retrieveRemoteFile_.callCount).toEqual(1);
});
it("subsequent read from the same URL should go from cache", function() {
jasmine.getFixtures().read(fixtureUrl, fixtureUrl);
- expect($.ajax.callCount).toEqual(1);
+ expect(jasmine.Fixtures.prototype.retrieveRemoteFile_.callCount).toEqual(1);
});
});
@@ -71,13 +72,13 @@ describe("jasmine.Fixtures", function() {
it("should use the configured fixtures path concatenating it to the requested url (without concatenating a slash if it already has an ending one)", function() {
jasmine.getFixtures().fixturesPath = 'a path ending with slash/'
readFixtures(fixtureUrl);
- expect($.ajax.mostRecentCall.args[0].url).toEqual('a path ending with slash/'+fixtureUrl);
+ expect(jasmine.Fixtures.prototype.retrieveRemoteFile_.mostRecentCall.args[0]).toEqual('a path ending with slash/'+fixtureUrl);
});
it("should use the configured fixtures path concatenating it to the requested url (concatenating a slash if it doesn't have an ending one)", function() {
jasmine.getFixtures().fixturesPath = 'a path without an ending slash'
readFixtures(fixtureUrl);
- expect($.ajax.mostRecentCall.args[0].url).toEqual('a path without an ending slash/'+fixtureUrl);
+ expect(jasmine.Fixtures.prototype.retrieveRemoteFile_.mostRecentCall.args[0]).toEqual('a path without an ending slash/'+fixtureUrl);
});
});
@@ -137,7 +138,7 @@ describe("jasmine.Fixtures", function() {
it("should go from cache", function() {
jasmine.getFixtures().preload(fixtureUrl, anotherFixtureUrl);
jasmine.getFixtures().read(fixtureUrl, anotherFixtureUrl);
- expect($.ajax.callCount).toEqual(2);
+ expect(jasmine.Fixtures.prototype.retrieveRemoteFile_.callCount).toEqual(2);
})
it("should return correct HTMLs", function() {
@@ -149,13 +150,13 @@ describe("jasmine.Fixtures", function() {
it("should not preload the same fixture twice", function() {
jasmine.getFixtures().preload(fixtureUrl, fixtureUrl);
- expect($.ajax.callCount).toEqual(1);
+ expect(jasmine.Fixtures.prototype.retrieveRemoteFile_.callCount).toEqual(1);
});
it("should have shortcut global method preloadFixtures", function() {
preloadFixtures(fixtureUrl, anotherFixtureUrl);
jasmine.getFixtures().read(fixtureUrl, anotherFixtureUrl);
- expect($.ajax.callCount).toEqual(2);
+ expect(jasmine.Fixtures.prototype.retrieveRemoteFile_.callCount).toEqual(2);
});
});

0 comments on commit c2f7dc7

Please sign in to comment.