jasmine-core 1.3.1 → 2.0.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. data/lib/jasmine-core.rb +14 -1
  2. data/lib/jasmine-core/boot.js +131 -0
  3. data/lib/jasmine-core/boot/boot.js +109 -0
  4. data/lib/jasmine-core/example/spec/PlayerSpec.js +2 -2
  5. data/lib/jasmine-core/example/spec/SpecHelper.js +14 -8
  6. data/lib/jasmine-core/jasmine-html.js +289 -616
  7. data/lib/jasmine-core/jasmine.css +52 -80
  8. data/lib/jasmine-core/jasmine.js +1972 -2211
  9. data/lib/jasmine-core/spec/console/ConsoleReporterSpec.js +161 -386
  10. data/lib/jasmine-core/spec/core/AnySpec.js +45 -0
  11. data/lib/jasmine-core/spec/core/CallTrackerSpec.js +105 -0
  12. data/lib/jasmine-core/spec/core/ClockSpec.js +314 -0
  13. data/lib/jasmine-core/spec/core/CustomMatchersSpec.js +96 -97
  14. data/lib/jasmine-core/spec/core/DelayedFunctionSchedulerSpec.js +179 -0
  15. data/lib/jasmine-core/spec/core/EnvSpec.js +454 -102
  16. data/lib/jasmine-core/spec/core/ExceptionFormatterSpec.js +56 -0
  17. data/lib/jasmine-core/spec/core/ExceptionsSpec.js +15 -126
  18. data/lib/jasmine-core/spec/core/ExpectationResultSpec.js +61 -0
  19. data/lib/jasmine-core/spec/core/ExpectationSpec.js +320 -0
  20. data/lib/jasmine-core/spec/core/JsApiReporterSpec.js +150 -38
  21. data/lib/jasmine-core/spec/core/ObjectContainingSpec.js +64 -0
  22. data/lib/jasmine-core/spec/core/PrettyPrintSpec.js +43 -42
  23. data/lib/jasmine-core/spec/core/QueueRunnerSpec.js +147 -0
  24. data/lib/jasmine-core/spec/core/ReportDispatcherSpec.js +40 -0
  25. data/lib/jasmine-core/spec/core/SpecRunningSpec.js +92 -1075
  26. data/lib/jasmine-core/spec/core/SpecSpec.js +215 -95
  27. data/lib/jasmine-core/spec/core/SpySpec.js +28 -196
  28. data/lib/jasmine-core/spec/core/SpyStrategySpec.js +101 -0
  29. data/lib/jasmine-core/spec/core/SuiteSpec.js +216 -106
  30. data/lib/jasmine-core/spec/core/TimerSpec.js +13 -0
  31. data/lib/jasmine-core/spec/core/UtilSpec.js +19 -30
  32. data/lib/jasmine-core/spec/core/matchers/matchersUtilSpec.js +219 -0
  33. data/lib/jasmine-core/spec/core/matchers/toBeCloseToSpec.js +51 -0
  34. data/lib/jasmine-core/spec/core/matchers/toBeDefinedSpec.js +18 -0
  35. data/lib/jasmine-core/spec/core/matchers/toBeFalsySpec.js +38 -0
  36. data/lib/jasmine-core/spec/core/matchers/toBeGreaterThanSpec.js +19 -0
  37. data/lib/jasmine-core/spec/core/matchers/toBeLessThanSpec.js +20 -0
  38. data/lib/jasmine-core/spec/core/matchers/toBeNaNSpec.js +36 -0
  39. data/lib/jasmine-core/spec/core/matchers/toBeNullSpec.js +17 -0
  40. data/lib/jasmine-core/spec/core/matchers/toBeSpec.js +17 -0
  41. data/lib/jasmine-core/spec/core/matchers/toBeTruthySpec.js +38 -0
  42. data/lib/jasmine-core/spec/core/matchers/toBeUndefinedSpec.js +17 -0
  43. data/lib/jasmine-core/spec/core/matchers/toContainSpec.js +24 -0
  44. data/lib/jasmine-core/spec/core/matchers/toEqualSpec.js +28 -0
  45. data/lib/jasmine-core/spec/core/matchers/toHaveBeenCalledSpec.js +46 -0
  46. data/lib/jasmine-core/spec/core/matchers/toHaveBeenCalledWithSpec.js +57 -0
  47. data/lib/jasmine-core/spec/core/matchers/toMatchSpec.js +34 -0
  48. data/lib/jasmine-core/spec/core/matchers/toThrowErrorSpec.js +280 -0
  49. data/lib/jasmine-core/spec/core/matchers/toThrowSpec.js +98 -0
  50. data/lib/jasmine-core/spec/helpers/BrowserFlags.js +19 -0
  51. data/lib/jasmine-core/spec/html/HtmlReporterSpec.js +494 -0
  52. data/lib/jasmine-core/spec/html/HtmlSpecFilterSpec.js +18 -0
  53. data/lib/jasmine-core/spec/html/MatchersHtmlSpec.js +8 -8
  54. data/lib/jasmine-core/spec/html/PrettyPrintHtmlSpec.js +3 -3
  55. data/lib/jasmine-core/spec/html/QueryStringSpec.js +43 -0
  56. data/lib/jasmine-core/spec/html/ResultsNodeSpec.js +62 -0
  57. data/lib/jasmine-core/spec/node_suite.js +137 -79
  58. data/lib/jasmine-core/spec/performance/performance_test.js +10 -0
  59. data/lib/jasmine-core/spec/support/dev_boot.js +118 -0
  60. data/lib/jasmine-core/version.rb +5 -2
  61. metadata +47 -103
  62. data/lib/jasmine-core/example/SpecRunner.html +0 -54
  63. data/lib/jasmine-core/spec/core/BaseSpec.js +0 -27
  64. data/lib/jasmine-core/spec/core/MatchersSpec.js +0 -1157
  65. data/lib/jasmine-core/spec/core/MockClockSpec.js +0 -38
  66. data/lib/jasmine-core/spec/core/MultiReporterSpec.js +0 -45
  67. data/lib/jasmine-core/spec/core/NestedResultsSpec.js +0 -54
  68. data/lib/jasmine-core/spec/core/QueueSpec.js +0 -23
  69. data/lib/jasmine-core/spec/core/ReporterSpec.js +0 -56
  70. data/lib/jasmine-core/spec/core/RunnerSpec.js +0 -280
  71. data/lib/jasmine-core/spec/core/WaitsForBlockSpec.js +0 -118
  72. data/lib/jasmine-core/spec/html/HTMLReporterSpec.js +0 -209
  73. data/lib/jasmine-core/spec/html/TrivialReporterSpec.js +0 -239
@@ -0,0 +1,56 @@
1
+ describe("ExceptionFormatter", function() {
2
+ describe("#message", function() {
3
+ it('formats Firefox exception messages', function() {
4
+ var sampleFirefoxException = {
5
+ fileName: 'foo.js',
6
+ lineNumber: '1978',
7
+ message: 'you got your foo in my bar',
8
+ name: 'A Classic Mistake'
9
+ },
10
+ exceptionFormatter = new j$.ExceptionFormatter(),
11
+ message = exceptionFormatter.message(sampleFirefoxException);
12
+
13
+ expect(message).toEqual('A Classic Mistake: you got your foo in my bar in foo.js (line 1978)');
14
+ });
15
+
16
+ it('formats Webkit exception messages', function() {
17
+ var sampleWebkitException = {
18
+ sourceURL: 'foo.js',
19
+ line: '1978',
20
+ message: 'you got your foo in my bar',
21
+ name: 'A Classic Mistake'
22
+ },
23
+ exceptionFormatter = new j$.ExceptionFormatter(),
24
+ message = exceptionFormatter.message(sampleWebkitException);
25
+
26
+ expect(message).toEqual('A Classic Mistake: you got your foo in my bar in foo.js (line 1978)');
27
+ });
28
+
29
+ it('formats V8 exception messages', function() {
30
+ var sampleV8 = {
31
+ message: 'you got your foo in my bar',
32
+ name: 'A Classic Mistake'
33
+ },
34
+ exceptionFormatter = new j$.ExceptionFormatter(),
35
+ message = exceptionFormatter.message(sampleV8);
36
+
37
+ expect(message).toEqual('A Classic Mistake: you got your foo in my bar');
38
+
39
+ });
40
+ });
41
+
42
+ describe("#stack", function() {
43
+ it("formats stack traces from Webkit, Firefox, node.js or IE10+", function() {
44
+ if (jasmine.getEnv().ieVersion < 10 || jasmine.getEnv().safariVersion < 6) { return; }
45
+
46
+ var error;
47
+ try { throw new Error("an error") } catch(e) { error = e; }
48
+
49
+ expect(new j$.ExceptionFormatter().stack(error)).toMatch(/ExceptionFormatterSpec\.js.*\d+/)
50
+ });
51
+
52
+ it("returns null if no Error provided", function() {
53
+ expect(new j$.ExceptionFormatter().stack()).toBeNull();
54
+ });
55
+ });
56
+ });
@@ -1,39 +1,14 @@
1
- describe('Exceptions:', function() {
1
+ xdescribe('Exceptions:', function() {
2
2
  var env;
3
3
 
4
4
  beforeEach(function() {
5
- env = new jasmine.Env();
5
+ env = new j$.Env();
6
6
  env.updateInterval = 0;
7
7
  });
8
8
 
9
- it('jasmine.formatException formats Firefox exception messages as expected', function() {
10
- var sampleFirefoxException = {
11
- fileName: 'foo.js',
12
- line: '1978',
13
- message: 'you got your foo in my bar',
14
- name: 'A Classic Mistake'
15
- };
16
-
17
- var expected = 'A Classic Mistake: you got your foo in my bar in foo.js (line 1978)';
18
-
19
- expect(jasmine.util.formatException(sampleFirefoxException)).toEqual(expected);
20
- });
21
-
22
- it('jasmine.formatException formats Webkit exception messages as expected', function() {
23
- var sampleWebkitException = {
24
- sourceURL: 'foo.js',
25
- lineNumber: '1978',
26
- message: 'you got your foo in my bar',
27
- name: 'A Classic Mistake'
28
- };
29
-
30
- var expected = 'A Classic Mistake: you got your foo in my bar in foo.js (line 1978)';
31
-
32
- expect(jasmine.util.formatException(sampleWebkitException)).toEqual(expected);
33
- });
34
-
35
9
  describe('with break on exception', function() {
36
10
  it('should not catch the exception', function() {
11
+ env.catchExceptions(false);
37
12
  var suite = env.describe('suite for break on exceptions', function() {
38
13
  env.it('should break when an exception is thrown', function() {
39
14
  throw new Error('I should hit a breakpoint!');
@@ -42,16 +17,11 @@ describe('Exceptions:', function() {
42
17
  var runner = env.currentRunner();
43
18
  var dont_change = 'I will never change!';
44
19
 
45
- var oldCatch = jasmine.CATCH_EXCEPTIONS;
46
- jasmine.CATCH_EXCEPTIONS = false;
47
20
  try {
48
21
  suite.execute();
49
22
  dont_change = 'oops I changed';
50
23
  }
51
24
  catch (e) {}
52
- finally {
53
- jasmine.CATCH_EXCEPTIONS = oldCatch;
54
- }
55
25
 
56
26
  expect(dont_change).toEqual('I will never change!');
57
27
  });
@@ -59,117 +29,36 @@ describe('Exceptions:', function() {
59
29
 
60
30
  describe("with catch on exception", function() {
61
31
  it('should handle exceptions thrown, but continue', function() {
62
- var fakeTimer = new jasmine.FakeTimer();
63
- env.setTimeout = fakeTimer.setTimeout;
64
- env.clearTimeout = fakeTimer.clearTimeout;
65
- env.setInterval = fakeTimer.setInterval;
66
- env.clearInterval = fakeTimer.clearInterval;
67
-
68
- //we run two exception tests to make sure we continue after throwing an exception
69
- var suite = env.describe('Suite for handles exceptions', function () {
32
+ var ranSecondTest = false,
33
+ suite = env.describe('Suite for handles exceptions', function () {
70
34
  env.it('should be a test that fails because it throws an exception', function() {
71
- throw new Error('fake error 1');
35
+ throw new Error();
72
36
  });
73
-
74
- env.it('should be another test that fails because it throws an exception', function() {
75
- this.runs(function () {
76
- throw new Error('fake error 2');
77
- });
78
- this.runs(function () {
79
- this.expect(true).toEqual(true);
80
- });
81
- });
82
-
83
- env.it('should be a passing test that runs after exceptions are thrown', function() {
84
- this.expect(true).toEqual(true);
85
- });
86
-
87
- env.it('should be another test that fails because it throws an exception after a wait', function() {
88
- this.runs(function () {
89
- var foo = 'foo';
90
- });
91
- this.waits(250);
92
- this.runs(function () {
93
- throw new Error('fake error 3');
94
- });
95
- });
96
-
97
37
  env.it('should be a passing test that runs after exceptions are thrown from a async test', function() {
98
- this.expect(true).toEqual(true);
38
+ ranSecondTest = true;
99
39
  });
100
40
  });
101
41
 
102
- var runner = env.currentRunner();
103
42
  suite.execute();
104
- fakeTimer.tick(2500);
105
-
106
- var suiteResults = suite.results();
107
- var specResults = suiteResults.getItems();
108
-
109
- expect(suiteResults.passed()).toEqual(false);
110
- //
111
- expect(specResults.length).toEqual(5);
112
- expect(specResults[0].passed()).toMatch(false);
113
- var blockResults = specResults[0].getItems();
114
- expect(blockResults[0].passed()).toEqual(false);
115
- expect(blockResults[0].message).toMatch(/fake error 1/);
116
-
117
- expect(specResults[1].passed()).toEqual(false);
118
- blockResults = specResults[1].getItems();
119
- expect(blockResults[0].passed()).toEqual(false);
120
- expect(blockResults[0].message).toMatch(/fake error 2/);
121
- expect(blockResults[1].passed()).toEqual(true);
122
-
123
- expect(specResults[2].passed()).toEqual(true);
124
-
125
- expect(specResults[3].passed()).toEqual(false);
126
- blockResults = specResults[3].getItems();
127
- expect(blockResults[0].message).toMatch(/fake error 3/);
128
-
129
- expect(specResults[4].passed()).toEqual(true);
43
+ expect(ranSecondTest).toBe(true);
130
44
  });
131
45
 
132
46
  it("should handle exceptions thrown directly in top-level describe blocks and continue", function () {
133
- var suite = env.describe("a top level describe block that throws an exception", function () {
47
+ var ranSecondDescribe = false, suite, suite2, runner = env.currentRunner();
48
+ suite = env.describe("a suite that throws an exception", function () {
134
49
  env.it("is a test that should pass", function () {
135
50
  this.expect(true).toEqual(true);
136
51
  });
137
52
 
138
53
  throw new Error("top level error");
139
54
  });
140
-
141
- suite.execute();
142
- var suiteResults = suite.results();
143
- var specResults = suiteResults.getItems();
144
-
145
- expect(suiteResults.passed()).toEqual(false);
146
- expect(specResults.length).toEqual(2);
147
-
148
- expect(specResults[1].description).toMatch(/encountered a declaration exception/);
149
- });
150
-
151
- it("should handle exceptions thrown directly in nested describe blocks and continue", function () {
152
- var suite = env.describe("a top level describe", function () {
153
- env.describe("a mid-level describe that throws an exception", function () {
154
- env.it("is a test that should pass", function () {
155
- this.expect(true).toEqual(true);
156
- });
157
-
158
- throw new Error("a mid-level error");
159
- });
55
+ suite2 = env.describe("a suite that doesn't throw an exception", function () {
56
+ ranSecondDescribe = true;
160
57
  });
161
58
 
162
- suite.execute();
163
- var suiteResults = suite.results();
164
- var specResults = suiteResults.getItems();
165
-
166
- expect(suiteResults.passed()).toEqual(false);
167
- expect(specResults.length).toEqual(1);
168
-
169
- var nestedSpecResults = specResults[0].getItems();
170
-
171
- expect(nestedSpecResults.length).toEqual(2);
172
- expect(nestedSpecResults[1].description).toMatch(/encountered a declaration exception/);
59
+ runner.execute();
60
+ expect(ranSecondDescribe).toBe(true);
173
61
  });
174
62
  });
63
+
175
64
  });
@@ -0,0 +1,61 @@
1
+ describe("buildExpectationResult", function() {
2
+ it("defaults to passed", function() {
3
+ var result = j$.buildExpectationResult({passed: 'some-value'});
4
+ expect(result.passed).toBe('some-value');
5
+ });
6
+
7
+ it("message defaults to Passed for passing specs", function() {
8
+ var result = j$.buildExpectationResult({passed: true, message: 'some-value'});
9
+ expect(result.message).toBe('Passed.');
10
+ });
11
+
12
+ it("message returns the message for failing expecations", function() {
13
+ var result = j$.buildExpectationResult({passed: false, message: 'some-value'});
14
+ expect(result.message).toBe('some-value');
15
+ });
16
+
17
+ it("delegates message formatting to the provided formatter if there was an Error", function() {
18
+ var fakeError = {message: 'foo'},
19
+ messageFormatter = jasmine.createSpy("exception message formatter").and.callReturn(fakeError.message);
20
+
21
+ var result = j$.buildExpectationResult(
22
+ {
23
+ passed: false,
24
+ error: fakeError,
25
+ messageFormatter: messageFormatter
26
+ });
27
+
28
+ expect(messageFormatter).toHaveBeenCalledWith(fakeError);
29
+ expect(result.message).toEqual('foo');
30
+ });
31
+
32
+ it("delegates stack formatting to the provided formatter if there was an Error", function() {
33
+ var fakeError = {stack: 'foo'},
34
+ stackFormatter = jasmine.createSpy("stack formatter").and.callReturn(fakeError.stack);
35
+
36
+ var result = j$.buildExpectationResult(
37
+ {
38
+ passed: false,
39
+ error: fakeError,
40
+ stackFormatter: stackFormatter
41
+ });
42
+
43
+ expect(stackFormatter).toHaveBeenCalledWith(fakeError);
44
+ expect(result.stack).toEqual('foo');
45
+ });
46
+
47
+ it("matcherName returns passed matcherName", function() {
48
+ var result = j$.buildExpectationResult({matcherName: 'some-value'});
49
+ expect(result.matcherName).toBe('some-value');
50
+ });
51
+
52
+ it("expected returns passed expected", function() {
53
+ var result = j$.buildExpectationResult({expected: 'some-value'});
54
+ expect(result.expected).toBe('some-value');
55
+ });
56
+
57
+ it("actual returns passed actual", function() {
58
+ var result = j$.buildExpectationResult({actual: 'some-value'});
59
+ expect(result.actual).toBe('some-value');
60
+ });
61
+ });
@@ -0,0 +1,320 @@
1
+ describe("Expectation", function() {
2
+ it(".addMatchers makes matchers available to any expectation", function() {
3
+ var matchers = {
4
+ toFoo: function() {},
5
+ toBar: function() {}
6
+ },
7
+ expectation;
8
+
9
+ j$.Expectation.addMatchers(matchers);
10
+
11
+ expectation = new j$.Expectation({});
12
+
13
+ expect(expectation.toFoo).toBeDefined();
14
+ expect(expectation.toBar).toBeDefined();
15
+ });
16
+
17
+ it(".addCoreMatchers makes matchers available to any expectation", function() {
18
+ var coreMatchers = {
19
+ toQuux: function() {}
20
+ },
21
+ expectation;
22
+
23
+ j$.Expectation.addCoreMatchers(coreMatchers);
24
+
25
+ expectation = new j$.Expectation({});
26
+
27
+ expect(expectation.toQuux).toBeDefined();
28
+ });
29
+
30
+ it(".resetMatchers should keep only core matchers", function() {
31
+ var matchers = {
32
+ toFoo: function() {}
33
+ },
34
+ coreMatchers = {
35
+ toQuux: function() {}
36
+ },
37
+ expectation;
38
+
39
+ j$.Expectation.addCoreMatchers(coreMatchers);
40
+ j$.Expectation.addMatchers(matchers);
41
+ j$.Expectation.resetMatchers();
42
+
43
+ expectation = new j$.Expectation({});
44
+
45
+ expect(expectation.toQuux).toBeDefined();
46
+ expect(expectation.toFoo).toBeUndefined();
47
+ });
48
+
49
+ it("Factory builds an expectaion/negative expectation", function() {
50
+ var builtExpectation = j$.Expectation.Factory();
51
+
52
+ expect(builtExpectation instanceof j$.Expectation).toBe(true);
53
+ expect(builtExpectation.not instanceof j$.Expectation).toBe(true);
54
+ expect(builtExpectation.not.isNot).toBe(true);
55
+ });
56
+
57
+ it("wraps matchers's compare functions, passing in matcher dependencies", function() {
58
+ var fakeCompare = function() { return { pass: true }; },
59
+ matcherFactory = jasmine.createSpy("matcher").and.callReturn({ compare: fakeCompare }),
60
+ matchers = {
61
+ toFoo: matcherFactory
62
+ },
63
+ util = {},
64
+ customEqualityTesters = ['a'],
65
+ addExpectationResult = jasmine.createSpy("addExpectationResult"),
66
+ expectation;
67
+
68
+ j$.Expectation.addMatchers(matchers);
69
+
70
+ expectation = new j$.Expectation({
71
+ util: util,
72
+ customEqualityTesters: customEqualityTesters,
73
+ actual: "an actual",
74
+ addExpectationResult: addExpectationResult
75
+ });
76
+
77
+ expectation.toFoo("hello");
78
+
79
+ expect(matcherFactory).toHaveBeenCalledWith(util, customEqualityTesters)
80
+ });
81
+
82
+ it("wraps matchers's compare functions, passing the actual and expected", function() {
83
+ var fakeCompare = jasmine.createSpy('fake-compare').and.callReturn({pass: true}),
84
+ matchers = {
85
+ toFoo: function() {
86
+ return {
87
+ compare: fakeCompare
88
+ };
89
+ }
90
+ },
91
+ util = {
92
+ buildFailureMessage: jasmine.createSpy('buildFailureMessage')
93
+ },
94
+ addExpectationResult = jasmine.createSpy("addExpectationResult"),
95
+ expectation;
96
+
97
+ j$.Expectation.addMatchers(matchers);
98
+
99
+ expectation = new j$.Expectation({
100
+ util: util,
101
+ actual: "an actual",
102
+ addExpectationResult: addExpectationResult
103
+ });
104
+
105
+ expectation.toFoo("hello");
106
+
107
+ expect(fakeCompare).toHaveBeenCalledWith("an actual", "hello");
108
+ });
109
+
110
+ it("reports a passing result to the spec when the comparison passes", function() {
111
+ var matchers = {
112
+ toFoo: function() {
113
+ return {
114
+ compare: function() { return { pass: true }; }
115
+ };
116
+ }
117
+ },
118
+ util = {
119
+ buildFailureMessage: jasmine.createSpy('buildFailureMessage')
120
+ },
121
+ addExpectationResult = jasmine.createSpy("addExpectationResult"),
122
+ expectation;
123
+
124
+ j$.Expectation.addMatchers(matchers);
125
+
126
+ expectation = new j$.Expectation({
127
+ matchers: matchers,
128
+ util: util,
129
+ actual: "an actual",
130
+ addExpectationResult: addExpectationResult
131
+ });
132
+
133
+ expectation.toFoo("hello");
134
+
135
+ expect(addExpectationResult).toHaveBeenCalledWith(true, {
136
+ matcherName: "toFoo",
137
+ passed: true,
138
+ message: "",
139
+ expected: "hello",
140
+ actual: "an actual"
141
+ });
142
+ });
143
+
144
+ it("reports a failing result to the spec when the comparison fails", function() {
145
+ var matchers = {
146
+ toFoo: function() {
147
+ return {
148
+ compare: function() { return { pass: false }; }
149
+ };
150
+ }
151
+ },
152
+ util = {
153
+ buildFailureMessage: function() { return ""; }
154
+ },
155
+ addExpectationResult = jasmine.createSpy("addExpectationResult"),
156
+ expectation;
157
+
158
+ j$.Expectation.addMatchers(matchers);
159
+
160
+ expectation = new j$.Expectation({
161
+ matchers: matchers,
162
+ util: util,
163
+ actual: "an actual",
164
+ addExpectationResult: addExpectationResult
165
+ });
166
+
167
+ expectation.toFoo("hello");
168
+
169
+ expect(addExpectationResult).toHaveBeenCalledWith(false, {
170
+ matcherName: "toFoo",
171
+ passed: false,
172
+ expected: "hello",
173
+ actual: "an actual",
174
+ message: ""
175
+ });
176
+ });
177
+
178
+ it("reports a failing result and a custom fail message to the spec when the comparison fails", function() {
179
+ var matchers = {
180
+ toFoo: function() {
181
+ return {
182
+ compare: function() {
183
+ return {
184
+ pass: false,
185
+ message: "I am a custom message"
186
+ };
187
+ }
188
+ };
189
+ }
190
+ },
191
+ addExpectationResult = jasmine.createSpy("addExpectationResult"),
192
+ expectation;
193
+
194
+ j$.Expectation.addMatchers(matchers);
195
+
196
+ expectation = new j$.Expectation({
197
+ matchers: matchers,
198
+ actual: "an actual",
199
+ addExpectationResult: addExpectationResult
200
+ });
201
+
202
+ expectation.toFoo("hello");
203
+
204
+ expect(addExpectationResult).toHaveBeenCalledWith(false, {
205
+ matcherName: "toFoo",
206
+ passed: false,
207
+ expected: "hello",
208
+ actual: "an actual",
209
+ message: "I am a custom message"
210
+ });
211
+ });
212
+
213
+ it("reports a passing result to the spec when the comparison fails for a negative expectation", function() {
214
+ var matchers = {
215
+ toFoo: function() {
216
+ return {
217
+ compare: function() { return { pass: false }; }
218
+ };
219
+ }
220
+ },
221
+ util = {
222
+ buildFailureMessage: function() { return ""; }
223
+ },
224
+ addExpectationResult = jasmine.createSpy("addExpectationResult"),
225
+ actual = "an actual",
226
+ expectation;
227
+
228
+ j$.Expectation.addMatchers(matchers);
229
+
230
+ expectation = new j$.Expectation({
231
+ matchers: matchers,
232
+ actual: "an actual",
233
+ addExpectationResult: addExpectationResult,
234
+ isNot: true
235
+ });
236
+
237
+ expectation.toFoo("hello");
238
+
239
+ expect(addExpectationResult).toHaveBeenCalledWith(true, {
240
+ matcherName: "toFoo",
241
+ passed: true,
242
+ message: "",
243
+ expected: "hello",
244
+ actual: actual
245
+ });
246
+ });
247
+
248
+ it("reports a failing result to the spec when the comparison passes for a negative expectation", function() {
249
+ var matchers = {
250
+ toFoo: function() {
251
+ return {
252
+ compare: function() { return { pass: true }; }
253
+ };
254
+ }
255
+ },
256
+ util = {
257
+ buildFailureMessage: function() { return "default messge"; }
258
+ },
259
+ addExpectationResult = jasmine.createSpy("addExpectationResult"),
260
+ actual = "an actual",
261
+ expectation;
262
+
263
+ j$.Expectation.addMatchers(matchers);
264
+
265
+ expectation = new j$.Expectation({
266
+ matchers: matchers,
267
+ actual: "an actual",
268
+ util: util,
269
+ addExpectationResult: addExpectationResult,
270
+ isNot: true
271
+ });
272
+
273
+ expectation.toFoo("hello");
274
+
275
+ expect(addExpectationResult).toHaveBeenCalledWith(false, {
276
+ matcherName: "toFoo",
277
+ passed: false,
278
+ expected: "hello",
279
+ actual: actual,
280
+ message: "default messge"
281
+ });
282
+ });
283
+
284
+ it("reports a failing result and a custom fail message to the spec when the comparison passes for a negative expectation", function() {
285
+ var matchers = {
286
+ toFoo: function() {
287
+ return {
288
+ compare: function() {
289
+ return {
290
+ pass: true,
291
+ message: "I am a custom message"
292
+ };
293
+ }
294
+ };
295
+ }
296
+ },
297
+ addExpectationResult = jasmine.createSpy("addExpectationResult"),
298
+ actual = "an actual",
299
+ expectation;
300
+
301
+ j$.Expectation.addMatchers(matchers);
302
+
303
+ expectation = new j$.Expectation({
304
+ matchers: matchers,
305
+ actual: "an actual",
306
+ addExpectationResult: addExpectationResult,
307
+ isNot: true
308
+ });
309
+
310
+ expectation.toFoo("hello");
311
+
312
+ expect(addExpectationResult).toHaveBeenCalledWith(false, {
313
+ matcherName: "toFoo",
314
+ passed: false,
315
+ expected: "hello",
316
+ actual: actual,
317
+ message: "I am a custom message"
318
+ });
319
+ });
320
+ });