jasmine-core 2.1.3 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/lib/console/console.js +1 -1
  3. data/lib/jasmine-core/boot.js +3 -2
  4. data/lib/jasmine-core/boot/boot.js +2 -1
  5. data/lib/jasmine-core/example/node_example/{src → lib/jasmine_examples}/Player.js +0 -0
  6. data/lib/jasmine-core/example/node_example/{src → lib/jasmine_examples}/Song.js +0 -0
  7. data/lib/jasmine-core/example/node_example/spec/{SpecHelper.js → helpers/jasmine_examples/SpecHelper.js} +0 -0
  8. data/lib/jasmine-core/example/node_example/spec/{PlayerSpec.js → jasmine_examples/PlayerSpec.js} +2 -2
  9. data/lib/jasmine-core/jasmine-html.js +17 -5
  10. data/lib/jasmine-core/jasmine.css +10 -10
  11. data/lib/jasmine-core/jasmine.js +295 -155
  12. data/lib/jasmine-core/node_boot.js +1 -1
  13. data/lib/jasmine-core/spec/core/DelayedFunctionSchedulerSpec.js +37 -0
  14. data/lib/jasmine-core/spec/core/EnvSpec.js +6 -0
  15. data/lib/jasmine-core/spec/core/PrettyPrintSpec.js +14 -14
  16. data/lib/jasmine-core/spec/core/SpecSpec.js +24 -1
  17. data/lib/jasmine-core/spec/core/SpyRegistrySpec.js +9 -0
  18. data/lib/jasmine-core/spec/core/SpySpec.js +9 -1
  19. data/lib/jasmine-core/spec/core/SuiteSpec.js +26 -0
  20. data/lib/jasmine-core/spec/core/{AnySpec.js → asymmetric_equality/AnySpec.js} +6 -6
  21. data/lib/jasmine-core/spec/core/asymmetric_equality/AnythingSpec.js +44 -0
  22. data/lib/jasmine-core/spec/core/asymmetric_equality/ArrayContainingSpec.js +39 -0
  23. data/lib/jasmine-core/spec/core/asymmetric_equality/ObjectContainingSpec.js +58 -0
  24. data/lib/jasmine-core/spec/core/asymmetric_equality/StringMatchingSpec.js +27 -0
  25. data/lib/jasmine-core/spec/core/integration/EnvSpec.js +79 -3
  26. data/lib/jasmine-core/spec/core/integration/SpecRunningSpec.js +26 -2
  27. data/lib/jasmine-core/spec/core/matchers/matchersUtilSpec.js +112 -2
  28. data/lib/jasmine-core/spec/core/matchers/toMatchSpec.js +8 -0
  29. data/lib/jasmine-core/spec/html/HtmlReporterSpec.js +19 -8
  30. data/lib/jasmine-core/spec/html/PrettyPrintHtmlSpec.js +1 -1
  31. data/lib/jasmine-core/spec/html/QueryStringSpec.js +32 -3
  32. data/lib/jasmine-core/version.rb +1 -1
  33. metadata +96 -93
  34. data/lib/jasmine-core/spec/core/ObjectContainingSpec.js +0 -70
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright (c) 2008-2014 Pivotal Labs
2
+ Copyright (c) 2008-2015 Pivotal Labs
3
3
 
4
4
  Permission is hereby granted, free of charge, to any person obtaining
5
5
  a copy of this software and associated documentation files (the
@@ -255,5 +255,42 @@ describe("DelayedFunctionScheduler", function() {
255
255
  scheduler.tick(10);
256
256
  });
257
257
 
258
+ it("removes functions during a tick that runs the function", function() {
259
+ var scheduler = new j$.DelayedFunctionScheduler(),
260
+ fn = jasmine.createSpy('fn'),
261
+ fnDelay = 10,
262
+ timeoutKey;
263
+
264
+ timeoutKey = scheduler.scheduleFunction(fn, fnDelay, [], true);
265
+ scheduler.scheduleFunction(function () {
266
+ scheduler.removeFunctionWithId(timeoutKey);
267
+ }, 2 * fnDelay);
268
+
269
+ expect(fn).not.toHaveBeenCalled();
270
+
271
+ scheduler.tick(3 * fnDelay);
272
+
273
+ expect(fn).toHaveBeenCalled();
274
+ expect(fn.calls.count()).toBe(2);
275
+ });
276
+
277
+ it("removes functions during the first tick that runs the function", function() {
278
+ var scheduler = new j$.DelayedFunctionScheduler(),
279
+ fn = jasmine.createSpy('fn'),
280
+ fnDelay = 10,
281
+ timeoutKey;
282
+
283
+ timeoutKey = scheduler.scheduleFunction(fn, fnDelay, [], true);
284
+ scheduler.scheduleFunction(function () {
285
+ scheduler.removeFunctionWithId(timeoutKey);
286
+ }, fnDelay);
287
+
288
+ expect(fn).not.toHaveBeenCalled();
289
+
290
+ scheduler.tick(3 * fnDelay);
291
+
292
+ expect(fn).toHaveBeenCalled();
293
+ expect(fn.calls.count()).toBe(1);
294
+ });
258
295
  });
259
296
 
@@ -11,6 +11,12 @@ describe("Env", function() {
11
11
  env.pending();
12
12
  }).toThrow(j$.Spec.pendingSpecExceptionMessage);
13
13
  });
14
+
15
+ it("throws the Pending Spec exception with a custom message", function() {
16
+ expect(function() {
17
+ env.pending('custom message');
18
+ }).toThrow(j$.Spec.pendingSpecExceptionMessage + 'custom message');
19
+ });
14
20
  });
15
21
 
16
22
  describe("#topSuite", function() {
@@ -16,7 +16,7 @@ describe("j$.pp", function () {
16
16
 
17
17
  it("should stringify arrays properly", function() {
18
18
  expect(j$.pp([1, 2])).toEqual("[ 1, 2 ]");
19
- expect(j$.pp([1, 'foo', {}, jasmine.undefined, null])).toEqual("[ 1, 'foo', { }, undefined, null ]");
19
+ expect(j$.pp([1, 'foo', {}, jasmine.undefined, null])).toEqual("[ 1, 'foo', Object({ }), undefined, null ]");
20
20
  });
21
21
 
22
22
  it("should indicate circular array references", function() {
@@ -32,18 +32,18 @@ describe("j$.pp", function () {
32
32
  });
33
33
 
34
34
  it("should stringify objects properly", function() {
35
- expect(j$.pp({foo: 'bar'})).toEqual("{ foo: 'bar' }");
36
- expect(j$.pp({foo:'bar', baz:3, nullValue: null, undefinedValue: jasmine.undefined})).toEqual("{ foo: 'bar', baz: 3, nullValue: null, undefinedValue: undefined }");
35
+ expect(j$.pp({foo: 'bar'})).toEqual("Object({ foo: 'bar' })");
36
+ expect(j$.pp({foo:'bar', baz:3, nullValue: null, undefinedValue: jasmine.undefined})).toEqual("Object({ foo: 'bar', baz: 3, nullValue: null, undefinedValue: undefined })");
37
37
  expect(j$.pp({foo: function () {
38
- }, bar: [1, 2, 3]})).toEqual("{ foo: Function, bar: [ 1, 2, 3 ] }");
38
+ }, bar: [1, 2, 3]})).toEqual("Object({ foo: Function, bar: [ 1, 2, 3 ] })");
39
39
  });
40
40
 
41
41
  it("should not include inherited properties when stringifying an object", function() {
42
- var SomeClass = function() {};
42
+ var SomeClass = function SomeClass() {};
43
43
  SomeClass.prototype.foo = "inherited foo";
44
44
  var instance = new SomeClass();
45
45
  instance.bar = "my own bar";
46
- expect(j$.pp(instance)).toEqual("{ bar: 'my own bar' }");
46
+ expect(j$.pp(instance)).toEqual("SomeClass({ bar: 'my own bar' })");
47
47
  });
48
48
 
49
49
  it("should not recurse objects and arrays more deeply than j$.MAX_PRETTY_PRINT_DEPTH", function() {
@@ -53,15 +53,15 @@ describe("j$.pp", function () {
53
53
 
54
54
  try {
55
55
  j$.MAX_PRETTY_PRINT_DEPTH = 2;
56
- expect(j$.pp(nestedObject)).toEqual("{ level1: { level2: Object } }");
56
+ expect(j$.pp(nestedObject)).toEqual("Object({ level1: Object({ level2: Object }) })");
57
57
  expect(j$.pp(nestedArray)).toEqual("[ 1, [ 2, Array ] ]");
58
58
 
59
59
  j$.MAX_PRETTY_PRINT_DEPTH = 3;
60
- expect(j$.pp(nestedObject)).toEqual("{ level1: { level2: { level3: Object } } }");
60
+ expect(j$.pp(nestedObject)).toEqual("Object({ level1: Object({ level2: Object({ level3: Object }) }) })");
61
61
  expect(j$.pp(nestedArray)).toEqual("[ 1, [ 2, [ 3, Array ] ] ]");
62
62
 
63
63
  j$.MAX_PRETTY_PRINT_DEPTH = 4;
64
- expect(j$.pp(nestedObject)).toEqual("{ level1: { level2: { level3: { level4: 'leaf' } } } }");
64
+ expect(j$.pp(nestedObject)).toEqual("Object({ level1: Object({ level2: Object({ level3: Object({ level4: 'leaf' }) }) }) })");
65
65
  expect(j$.pp(nestedArray)).toEqual("[ 1, [ 2, [ 3, [ 4, 'leaf' ] ] ] ]");
66
66
  } finally {
67
67
  j$.MAX_PRETTY_PRINT_DEPTH = originalMaxDepth;
@@ -73,7 +73,7 @@ describe("j$.pp", function () {
73
73
  var frozenObject = {foo: {bar: 'baz'}};
74
74
  frozenObject.circular = frozenObject;
75
75
  frozenObject = Object.freeze(frozenObject);
76
- expect(j$.pp(frozenObject)).toEqual("{ foo: { bar: 'baz' }, circular: <circular reference: Object> }");
76
+ expect(j$.pp(frozenObject)).toEqual("Object({ foo: Object({ bar: 'baz' }), circular: <circular reference: Object> })");
77
77
  }
78
78
  });
79
79
 
@@ -96,7 +96,7 @@ describe("j$.pp", function () {
96
96
  it("should indicate circular object references", function() {
97
97
  var sampleValue = {foo: 'hello'};
98
98
  sampleValue.nested = sampleValue;
99
- expect(j$.pp(sampleValue)).toEqual("{ foo: 'hello', nested: <circular reference: Object> }");
99
+ expect(j$.pp(sampleValue)).toEqual("Object({ foo: 'hello', nested: <circular reference: Object> })");
100
100
  });
101
101
 
102
102
  it("should indicate getters on objects as such", function() {
@@ -108,10 +108,10 @@ describe("j$.pp", function () {
108
108
  });
109
109
  }
110
110
  if (sampleValue.__defineGetter__) {
111
- expect(j$.pp(sampleValue)).toEqual("{ id: 1, calculatedValue: <getter> }");
111
+ expect(j$.pp(sampleValue)).toEqual("Object({ id: 1, calculatedValue: <getter> })");
112
112
  }
113
113
  else {
114
- expect(j$.pp(sampleValue)).toEqual("{ id: 1 }");
114
+ expect(j$.pp(sampleValue)).toEqual("Object({ id: 1 })");
115
115
  }
116
116
  });
117
117
 
@@ -157,6 +157,6 @@ describe("j$.pp", function () {
157
157
  var obj = Object.create(null);
158
158
  obj.foo = 'bar';
159
159
 
160
- expect(j$.pp(obj)).toEqual("{ foo: 'bar' }");
160
+ expect(j$.pp(obj)).toEqual("null({ foo: 'bar' })");
161
161
  });
162
162
  });
@@ -14,6 +14,10 @@ describe("Spec", function() {
14
14
  expect(j$.Spec.isPendingSpecException(fakeError)).toBe(true);
15
15
  });
16
16
 
17
+ it("#isPendingSpecException returns true for a pending spec exception with a custom message", function() {
18
+ expect(j$.Spec.isPendingSpecException(j$.Spec.pendingSpecExceptionMessage + 'foo')).toBe(true);
19
+ });
20
+
17
21
  it("#isPendingSpecException returns false for not a pending spec exception", function() {
18
22
  var e = new Error("foo");
19
23
 
@@ -174,7 +178,8 @@ describe("Spec", function() {
174
178
  description: 'with a spec',
175
179
  fullName: 'a suite with a spec',
176
180
  failedExpectations: [],
177
- passedExpectations: []
181
+ passedExpectations: [],
182
+ pendingReason: ''
178
183
  });
179
184
  });
180
185
 
@@ -254,6 +259,24 @@ describe("Spec", function() {
254
259
  spec.execute();
255
260
 
256
261
  expect(spec.status()).toEqual("pending");
262
+ expect(spec.result.pendingReason).toEqual('');
263
+ });
264
+
265
+ it("should set the pendingReason", function() {
266
+ var fakeQueueRunner = function(opts) {
267
+ opts.onException(new Error(j$.Spec.pendingSpecExceptionMessage + 'custom message'));
268
+ },
269
+ spec = new j$.Spec({
270
+ description: 'my test',
271
+ id: 'some-id',
272
+ queueableFn: { fn: function() { } },
273
+ queueRunnerFactory: fakeQueueRunner
274
+ });
275
+
276
+ spec.execute();
277
+
278
+ expect(spec.status()).toEqual("pending");
279
+ expect(spec.result.pendingReason).toEqual('custom message');
257
280
  });
258
281
  });
259
282
  });
@@ -7,6 +7,15 @@ describe("SpyRegistry", function() {
7
7
  }).toThrowError(/could not find an object/);
8
8
  });
9
9
 
10
+ it("checks that a method name was passed", function() {
11
+ var spyRegistry = new j$.SpyRegistry(),
12
+ subject = {};
13
+
14
+ expect(function() {
15
+ spyRegistry.spyOn(subject);
16
+ }).toThrowError(/No method name supplied/);
17
+ });
18
+
10
19
  it("checks for the existence of the method", function() {
11
20
  var spyRegistry = new j$.SpyRegistry(),
12
21
  subject = {};
@@ -7,7 +7,7 @@ describe('Spies', function () {
7
7
  TestClass.prototype.someFunction = function() {};
8
8
  TestClass.prototype.someFunction.bob = "test";
9
9
  });
10
-
10
+
11
11
  it("preserves the properties of the spied function", function() {
12
12
  var spy = j$.createSpy(TestClass.prototype, TestClass.prototype.someFunction);
13
13
 
@@ -68,6 +68,14 @@ describe('Spies', function () {
68
68
  expect(spyObj.method2.and.identity()).toEqual('BaseName.method2');
69
69
  });
70
70
 
71
+ it("should allow you to omit the baseName", function() {
72
+ var spyObj = j$.createSpyObj(['method1', 'method2']);
73
+
74
+ expect(spyObj).toEqual({ method1: jasmine.any(Function), method2: jasmine.any(Function)});
75
+ expect(spyObj.method1.and.identity()).toEqual('unknown.method1');
76
+ expect(spyObj.method2.and.identity()).toEqual('unknown.method2');
77
+ });
78
+
71
79
  it("should throw if you do not pass an array argument", function() {
72
80
  expect(function() {
73
81
  j$.createSpyObj('BaseName');
@@ -117,6 +117,32 @@ describe("Suite", function() {
117
117
  expect(lastAfter).toHaveBeenCalled();
118
118
  });
119
119
 
120
+ it("does not run *All functions if runnables are explicitly set", function(){
121
+ var env = new j$.Env(),
122
+ fakeQueueRunner = jasmine.createSpy('fake queue runner'),
123
+ suite = new j$.Suite({
124
+ env: env,
125
+ description: "I am a suite",
126
+ queueRunner: fakeQueueRunner,
127
+ runnablesExplictlySetGetter: function(){return true;}
128
+ }),
129
+ beforeAll = jasmine.createSpy('beforeAll'),
130
+ afterAll = jasmine.createSpy('afterAll'),
131
+ fakeIt = {execute: jasmine.createSpy('it'), isExecutable: function() { return true; } };
132
+
133
+ suite.beforeAll(beforeAll);
134
+ suite.afterAll(afterAll);
135
+ suite.addChild(fakeIt);
136
+
137
+ suite.execute();
138
+ var suiteFns = fakeQueueRunner.calls.mostRecent().args[0].queueableFns;
139
+
140
+ expect(suite.isExecutable()).toBeFalsy();
141
+ expect(suiteFns.length).toEqual(1);
142
+ expect(beforeAll).not.toHaveBeenCalled();
143
+ expect(afterAll).not.toHaveBeenCalled();
144
+ });
145
+
120
146
  it("can be disabled, but still calls callbacks", function() {
121
147
  var env = new j$.Env(),
122
148
  fakeQueueRunner = jasmine.createSpy('fake queue runner'),
@@ -2,38 +2,38 @@ describe("Any", function() {
2
2
  it("matches a string", function() {
3
3
  var any = new j$.Any(String);
4
4
 
5
- expect(any.jasmineMatches("foo")).toBe(true);
5
+ expect(any.asymmetricMatch("foo")).toBe(true);
6
6
  });
7
7
 
8
8
  it("matches a number", function() {
9
9
  var any = new j$.Any(Number);
10
10
 
11
- expect(any.jasmineMatches(1)).toBe(true);
11
+ expect(any.asymmetricMatch(1)).toBe(true);
12
12
  });
13
13
 
14
14
  it("matches a function", function() {
15
15
  var any = new j$.Any(Function);
16
16
 
17
- expect(any.jasmineMatches(function(){})).toBe(true);
17
+ expect(any.asymmetricMatch(function(){})).toBe(true);
18
18
  });
19
19
 
20
20
  it("matches an Object", function() {
21
21
  var any = new j$.Any(Object);
22
22
 
23
- expect(any.jasmineMatches({})).toBe(true);
23
+ expect(any.asymmetricMatch({})).toBe(true);
24
24
  });
25
25
 
26
26
  it("matches a Boolean", function() {
27
27
  var any = new j$.Any(Boolean);
28
28
 
29
- expect(any.jasmineMatches(true)).toBe(true);
29
+ expect(any.asymmetricMatch(true)).toBe(true);
30
30
  });
31
31
 
32
32
  it("matches another constructed object", function() {
33
33
  var Thing = function() {},
34
34
  any = new j$.Any(Thing);
35
35
 
36
- expect(any.jasmineMatches(new Thing())).toBe(true);
36
+ expect(any.asymmetricMatch(new Thing())).toBe(true);
37
37
  });
38
38
 
39
39
  it("jasmineToString's itself", function() {
@@ -0,0 +1,44 @@
1
+ describe("Anything", function() {
2
+ it("matches a string", function() {
3
+ var anything = new j$.Anything();
4
+
5
+ expect(anything.asymmetricMatch('foo')).toBe(true);
6
+ });
7
+
8
+ it("matches a number", function() {
9
+ var anything = new j$.Anything();
10
+
11
+ expect(anything.asymmetricMatch(42)).toBe(true);
12
+ });
13
+
14
+ it("matches an object", function() {
15
+ var anything = new j$.Anything();
16
+
17
+ expect(anything.asymmetricMatch({ foo: 'bar' })).toBe(true);
18
+ });
19
+
20
+ it("matches an array", function() {
21
+ var anything = new j$.Anything();
22
+
23
+ expect(anything.asymmetricMatch([1,2,3])).toBe(true);
24
+ });
25
+
26
+ it("doesn't match undefined", function() {
27
+ var anything = new j$.Anything();
28
+
29
+ expect(anything.asymmetricMatch()).toBe(false);
30
+ expect(anything.asymmetricMatch(undefined)).toBe(false);
31
+ });
32
+
33
+ it("doesn't match null", function() {
34
+ var anything = new j$.Anything();
35
+
36
+ expect(anything.asymmetricMatch(null)).toBe(false);
37
+ });
38
+
39
+ it("jasmineToString's itself", function() {
40
+ var anything = new j$.Anything();
41
+
42
+ expect(anything.jasmineToString()).toEqual("<jasmine.anything>");
43
+ });
44
+ });
@@ -0,0 +1,39 @@
1
+ describe("ArrayContaining", function() {
2
+ it("matches any actual to an empty array", function() {
3
+ var containing = new j$.ArrayContaining([]);
4
+
5
+ expect(containing.asymmetricMatch("foo")).toBe(true);
6
+ });
7
+
8
+ it("does not work when not passed an array", function() {
9
+ var containing = new j$.ArrayContaining("foo");
10
+
11
+ expect(function() {
12
+ containing.asymmetricMatch([]);
13
+ }).toThrowError(/not 'foo'/);
14
+ });
15
+
16
+ it("matches when the item is in the actual", function() {
17
+ var containing = new j$.ArrayContaining(["foo"]);
18
+
19
+ expect(containing.asymmetricMatch(["foo"])).toBe(true);
20
+ });
21
+
22
+ it("matches when additional items are in the actual", function() {
23
+ var containing = new j$.ArrayContaining(["foo"]);
24
+
25
+ expect(containing.asymmetricMatch(["foo", "bar"])).toBe(true);
26
+ });
27
+
28
+ it("does not match when the item is not in the actual", function() {
29
+ var containing = new j$.ArrayContaining(["foo"]);
30
+
31
+ expect(containing.asymmetricMatch(["bar"])).toBe(false);
32
+ });
33
+
34
+ it("jasmineToStrings itself", function() {
35
+ var containing = new j$.ArrayContaining([]);
36
+
37
+ expect(containing.jasmineToString()).toMatch("<jasmine.arrayContaining");
38
+ });
39
+ });
@@ -0,0 +1,58 @@
1
+ describe("ObjectContaining", function() {
2
+
3
+ it("matches any actual to an empty object", function() {
4
+ var containing = new j$.ObjectContaining({});
5
+
6
+ expect(containing.asymmetricMatch("foo")).toBe(true);
7
+ });
8
+
9
+ it("does not match an empty object actual", function() {
10
+ var containing = new j$.ObjectContaining("foo");
11
+
12
+ expect(function() {
13
+ containing.asymmetricMatch({})
14
+ }).toThrowError(/not 'foo'/)
15
+ });
16
+
17
+ it("matches when the key/value pair is present in the actual", function() {
18
+ var containing = new j$.ObjectContaining({foo: "fooVal"});
19
+
20
+ expect(containing.asymmetricMatch({foo: "fooVal", bar: "barVal"})).toBe(true);
21
+ });
22
+
23
+ it("does not match when the key/value pair is not present in the actual", function() {
24
+ var containing = new j$.ObjectContaining({foo: "fooVal"});
25
+
26
+ expect(containing.asymmetricMatch({bar: "barVal", quux: "quuxVal"})).toBe(false);
27
+ });
28
+
29
+ it("does not match when the key is present but the value is different in the actual", function() {
30
+ var containing = new j$.ObjectContaining({foo: "other"});
31
+
32
+ expect(containing.asymmetricMatch({foo: "fooVal", bar: "barVal"})).toBe(false);
33
+ });
34
+
35
+ it("jasmineToString's itself", function() {
36
+ var containing = new j$.ObjectContaining({});
37
+
38
+ expect(containing.jasmineToString()).toMatch("<jasmine.objectContaining");
39
+ });
40
+
41
+ it("matches recursively", function() {
42
+ var containing = new j$.ObjectContaining({one: new j$.ObjectContaining({two: {}})});
43
+
44
+ expect(containing.asymmetricMatch({one: {two: {}}})).toBe(true);
45
+ });
46
+
47
+ it("matches when key is present with undefined value", function() {
48
+ var containing = new j$.ObjectContaining({ one: undefined });
49
+
50
+ expect(containing.asymmetricMatch({ one: undefined })).toBe(true);
51
+ });
52
+
53
+ it("does not match when key with undefined value is not present", function() {
54
+ var containing = new j$.ObjectContaining({ one: undefined });
55
+
56
+ expect(containing.asymmetricMatch({})).toBe(false);
57
+ });
58
+ });