This repository has been archived by the owner on Mar 17, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
sugar.js
52 lines (45 loc) · 2.52 KB
/
sugar.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Syntactic sugar to make specs more like Rspec
exports.sugar = function() {
var Sugar = {
should_be: function(compare) { expect(this).toEqual(compare); },
should_be_a: function(object) { expect(this.constructor).toEqual(object) },
should_be_an_instance_of: function(object) { expect(true).toEqual(this instanceof(object)) },
should_not_be: function(compare) { expect(this).not.toEqual(compare); },
should_match: function(compare) { expect(this).toMatch(compare); },
should_not_match: function(compare) { expect(this).not.toMatch(compare); },
should_have_been_called: function() { expect(this).toHaveBeenCalled(); },
should_have_been_called_with: function() {
var expectation = expect(this);
expectation.toHaveBeenCalledWith.apply(expectation, arguments);
},
should_have_not_been_called: function() { expect(this).not.toHaveBeenCalled(); }
}
// Object.prototype.emitJasmine = function() { return this };
String.prototype.emitJasmine = function() { return this };
Number.prototype.emitJasmine = function() { return this };
Array.prototype.emitJasmine = function() { return this };
String.prototype.should_be = Sugar.should_be
Number.prototype.should_be = Sugar.should_be
Array.prototype.should_be = Sugar.should_be
String.prototype.should_not_be = Sugar.should_not_be
Number.prototype.should_not_be = Sugar.should_not_be
Array.prototype.should_not_be = Sugar.should_not_be
String.prototype.should_be_a = Sugar.should_be_a
Number.prototype.should_be_a = Sugar.should_be_a
Array.prototype.should_be_a = Sugar.should_be_a
Function.prototype.should_be_a = Sugar.should_be_a
String.prototype.should_match = Sugar.should_match
String.prototype.should_not_match = Sugar.should_not_match
Function.prototype.should_have_been_called = Sugar.should_have_been_called
Function.prototype.should_have_not_been_called = Sugar.should_have_not_been_called
Function.prototype.should_have_been_called_with = Sugar.should_have_been_called_with
};
// Extend jasmine.PrettyPrinter#format to try a emitJasmine method on an object - it is used when sugar is loaded
var originalformat = jasmine.PrettyPrinter.prototype.format;
jasmine.PrettyPrinter.prototype.format = function(value) {
if (value && value.emitJasmine) {
this.append(value.emitJasmine());
} else {
originalformat.apply(this, arguments)
}
};