Newer
Older
// Add custom matchers here, in a beforeEach block. Example:
//beforeEach(function() {
// this.addMatchers({
// toBePlaying: function(expectedSong) {
// var player = this.actual;
// return player.currentlyPlayingSong === expectedSong
// && player.isPlaying;
// }
// })
//});
beforeEach(function() {
danielgrippi
a validé
$('#jasmine_content').html(spec.readFixture("underscore_templates"));
// NOTE Commented (as well as in afterEach) to keep the listeners from rails.js alive.
//spec.clearLiveEventBindings();
jasmine.Clock.useMock();
Diaspora.Pages.TestPage = function() {
var self = this;
this.subscribe("page/ready", function() {
self.directionDetector = self.instantiate("DirectionDetector");
});
};
danielgrippi
a validé
var Page = Diaspora.Pages["TestPage"];
$.extend(Page.prototype, Diaspora.EventBroker.extend(Diaspora.BaseWidget));
Diaspora.page = new Page();
Diaspora.page.publish("page/ready", [$(document.body)])
});
afterEach(function() {
expect(spec.loadFixtureCount).toBeLessThan(2);
spec.loadFixtureCount = 0;
});
var context = describe;
var spec = {};
window.stubView = function stubView(text){
var stubClass = Backbone.View.extend({
render : function(){
$(this.el).html(text);
return this
}
})
return new stubClass
}
window.loginAs = function loginAs(attrs){
return app.currentUser = app.user(factory.userAttrs(attrs))
}
window.logout = function logout(){
danielgrippi
a validé
this.app._user = undefined
return app.currentUser = new app.models.User()
spec.clearLiveEventBindings = function() {
var events = jQuery.data(document, "events");
for (prop in events) {
delete events[prop];
}
};
spec.content = function() {
return $('#jasmine_content');
};
// Loads fixure markup into the DOM as a child of the jasmine_content div
spec.loadFixture = function(fixtureName) {
var $destination = $('#jasmine_content');
// get the markup, inject it into the dom
$destination.html(spec.fixtureHtml(fixtureName));
// keep track of fixture count to fail specs that
// call loadFixture() more than once
spec.loadFixtureCount++;
};
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// Returns fixture markup as a string. Useful for fixtures that
// represent the response text of ajax requests.
spec.readFixture = function(fixtureName) {
return spec.fixtureHtml(fixtureName);
};
spec.fixtureHtml = function(fixtureName) {
if (!spec.cachedFixtures[fixtureName]) {
spec.cachedFixtures[fixtureName] = spec.retrieveFixture(fixtureName);
}
return spec.cachedFixtures[fixtureName];
};
spec.retrieveFixture = function(fixtureName) {
// construct a path to the fixture, including a cache-busting timestamp
var path = '/tmp/js_dom_fixtures/' + fixtureName + ".fixture.html?" + new Date().getTime();
var xhr;
// retrieve the fixture markup via xhr request to jasmine server
try {
xhr = new jasmine.XmlHttpRequest();
xhr.open("GET", path, false);
xhr.send(null);
} catch(e) {
throw new Error("couldn't fetch " + path + ": " + e);
}
var regExp = new RegExp(/Couldn\\\'t load \/fixture/);
if (regExp.test(xhr.responseText)) {
throw new Error("Couldn't load fixture with key: '" + fixtureName + "'. No such file: '" + path + "'.");
}
return xhr.responseText;
};
danielgrippi
a validé
spec.loadFixtureCount = 0;