josephholsten-jasmine 1.1.0.pre.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +11 -0
- data/.gitmodules +3 -0
- data/Gemfile +5 -0
- data/HOW_TO_TEST.markdown +9 -0
- data/MIT.LICENSE +20 -0
- data/README.markdown +71 -0
- data/RELEASE.markdown +22 -0
- data/Rakefile +76 -0
- data/bin/jasmine +6 -0
- data/generators/jasmine/jasmine_generator.rb +32 -0
- data/generators/jasmine/templates/INSTALL +9 -0
- data/generators/jasmine/templates/jasmine-example/SpecRunner.html +27 -0
- data/generators/jasmine/templates/jasmine-example/spec/PlayerSpec.js +58 -0
- data/generators/jasmine/templates/jasmine-example/spec/SpecHelper.js +9 -0
- data/generators/jasmine/templates/jasmine-example/src/Player.js +22 -0
- data/generators/jasmine/templates/jasmine-example/src/Song.js +7 -0
- data/generators/jasmine/templates/lib/tasks/jasmine.rake +8 -0
- data/generators/jasmine/templates/spec/javascripts/support/jasmine-rails.yml +81 -0
- data/generators/jasmine/templates/spec/javascripts/support/jasmine.yml +73 -0
- data/generators/jasmine/templates/spec/javascripts/support/jasmine_config.rb +23 -0
- data/generators/jasmine/templates/spec/javascripts/support/jasmine_runner.rb +32 -0
- data/jasmine/Gemfile +6 -0
- data/jasmine/Gemfile.lock +33 -0
- data/jasmine/HowToRelease.markdown +29 -0
- data/jasmine/MIT.LICENSE +20 -0
- data/jasmine/README.markdown +50 -0
- data/jasmine/Rakefile +166 -0
- data/jasmine/cruise_config.rb +21 -0
- data/jasmine/example/SpecRunner.html +27 -0
- data/jasmine/example/spec/PlayerSpec.js +58 -0
- data/jasmine/example/spec/SpecHelper.js +9 -0
- data/jasmine/example/src/Player.js +22 -0
- data/jasmine/example/src/Song.js +7 -0
- data/jasmine/images/jasmine_favicon.png +0 -0
- data/jasmine/jsdoc-template/allclasses.tmpl +17 -0
- data/jasmine/jsdoc-template/allfiles.tmpl +56 -0
- data/jasmine/jsdoc-template/class.tmpl +646 -0
- data/jasmine/jsdoc-template/index.tmpl +39 -0
- data/jasmine/jsdoc-template/publish.js +184 -0
- data/jasmine/jsdoc-template/static/default.css +162 -0
- data/jasmine/jsdoc-template/static/header.html +2 -0
- data/jasmine/jsdoc-template/static/index.html +19 -0
- data/jasmine/jsdoc-template/symbol.tmpl +35 -0
- data/jasmine/jshint/jshint.js +5919 -0
- data/jasmine/jshint/run.js +98 -0
- data/jasmine/lib/jasmine-html.js +190 -0
- data/jasmine/lib/jasmine.css +166 -0
- data/jasmine/lib/jasmine.js +2445 -0
- data/jasmine/lib/json2.js +478 -0
- data/jasmine/spec/node_suite.js +233 -0
- data/jasmine/spec/runner.html +82 -0
- data/jasmine/spec/suites/BaseSpec.js +27 -0
- data/jasmine/spec/suites/CustomMatchersSpec.js +97 -0
- data/jasmine/spec/suites/EnvSpec.js +158 -0
- data/jasmine/spec/suites/ExceptionsSpec.js +107 -0
- data/jasmine/spec/suites/JsApiReporterSpec.js +103 -0
- data/jasmine/spec/suites/MatchersSpec.js +795 -0
- data/jasmine/spec/suites/MockClockSpec.js +38 -0
- data/jasmine/spec/suites/MultiReporterSpec.js +45 -0
- data/jasmine/spec/suites/NestedResultsSpec.js +54 -0
- data/jasmine/spec/suites/PrettyPrintSpec.js +93 -0
- data/jasmine/spec/suites/QueueSpec.js +23 -0
- data/jasmine/spec/suites/ReporterSpec.js +56 -0
- data/jasmine/spec/suites/RunnerSpec.js +267 -0
- data/jasmine/spec/suites/SpecRunningSpec.js +1253 -0
- data/jasmine/spec/suites/SpecSpec.js +124 -0
- data/jasmine/spec/suites/SpySpec.js +201 -0
- data/jasmine/spec/suites/SuiteSpec.js +120 -0
- data/jasmine/spec/suites/TrivialConsoleReporterSpec.js +431 -0
- data/jasmine/spec/suites/TrivialReporterSpec.js +238 -0
- data/jasmine/spec/suites/UtilSpec.js +39 -0
- data/jasmine/spec/suites/WaitsForBlockSpec.js +118 -0
- data/jasmine/src/Block.js +22 -0
- data/jasmine/src/Env.js +264 -0
- data/jasmine/src/JsApiReporter.js +102 -0
- data/jasmine/src/Matchers.js +354 -0
- data/jasmine/src/MultiReporter.js +35 -0
- data/jasmine/src/NestedResults.js +80 -0
- data/jasmine/src/PrettyPrinter.js +123 -0
- data/jasmine/src/Queue.js +99 -0
- data/jasmine/src/Reporter.js +31 -0
- data/jasmine/src/Runner.js +77 -0
- data/jasmine/src/Spec.js +242 -0
- data/jasmine/src/Suite.js +82 -0
- data/jasmine/src/WaitsBlock.js +15 -0
- data/jasmine/src/WaitsForBlock.js +54 -0
- data/jasmine/src/base.js +608 -0
- data/jasmine/src/console/TrivialConsoleReporter.js +144 -0
- data/jasmine/src/html/TrivialReporter.js +190 -0
- data/jasmine/src/html/jasmine.css +166 -0
- data/jasmine/src/mock-timeout.js +183 -0
- data/jasmine/src/util.js +67 -0
- data/jasmine/src/version.json +5 -0
- data/jasmine.gemspec +52 -0
- data/lib/generators/jasmine/examples/USAGE +11 -0
- data/lib/generators/jasmine/examples/examples_generator.rb +19 -0
- data/lib/generators/jasmine/examples/templates/public/javascripts/jasmine_examples/Player.js +22 -0
- data/lib/generators/jasmine/examples/templates/public/javascripts/jasmine_examples/Song.js +7 -0
- data/lib/generators/jasmine/examples/templates/spec/javascripts/helpers/SpecHelper.js +9 -0
- data/lib/generators/jasmine/examples/templates/spec/javascripts/jasmine_examples/PlayerSpec.js +58 -0
- data/lib/generators/jasmine/install/USAGE +11 -0
- data/lib/generators/jasmine/install/install_generator.rb +18 -0
- data/lib/generators/jasmine/install/templates/spec/javascripts/helpers/.gitkeep +0 -0
- data/lib/generators/jasmine/install/templates/spec/javascripts/support/jasmine.yml +81 -0
- data/lib/generators/jasmine/install/templates/spec/javascripts/support/jasmine_config.rb +23 -0
- data/lib/generators/jasmine/install/templates/spec/javascripts/support/jasmine_runner.rb +20 -0
- data/lib/generators/jasmine/jasmine_generator.rb +32 -0
- data/lib/generators/jasmine/templates/INSTALL +9 -0
- data/lib/generators/jasmine/templates/lib/tasks/jasmine.rake +2 -0
- data/lib/generators/jasmine/templates/spec/javascripts/support/jasmine-rails.yml +81 -0
- data/lib/generators/jasmine/templates/spec/javascripts/support/jasmine.yml +73 -0
- data/lib/generators/jasmine/templates/spec/javascripts/support/jasmine_config.rb +23 -0
- data/lib/generators/jasmine/templates/spec/javascripts/support/jasmine_runner.rb +32 -0
- data/lib/jasmine/base.rb +66 -0
- data/lib/jasmine/command_line_tool.rb +72 -0
- data/lib/jasmine/config.rb +190 -0
- data/lib/jasmine/railtie.rb +20 -0
- data/lib/jasmine/run.html.erb +44 -0
- data/lib/jasmine/selenium_driver.rb +49 -0
- data/lib/jasmine/server.rb +106 -0
- data/lib/jasmine/spec_builder.rb +162 -0
- data/lib/jasmine/tasks/jasmine.rake +44 -0
- data/lib/jasmine/version.rb +3 -0
- data/lib/jasmine.rb +14 -0
- data/spec/config_spec.rb +308 -0
- data/spec/fixture/jasmine.erb.yml +4 -0
- data/spec/jasmine_command_line_tool_spec.rb +29 -0
- data/spec/jasmine_pojs_spec.rb +51 -0
- data/spec/jasmine_rails2_spec.rb +93 -0
- data/spec/jasmine_rails3_spec.rb +71 -0
- data/spec/jasmine_self_test_config.rb +15 -0
- data/spec/jasmine_self_test_spec.rb +24 -0
- data/spec/server_spec.rb +80 -0
- data/spec/spec_helper.rb +65 -0
- metadata +386 -0
@@ -0,0 +1,431 @@
|
|
1
|
+
if (jasmine.TrivialConsoleReporter) {
|
2
|
+
describe("TrivialConsoleReporter", function() {
|
3
|
+
|
4
|
+
|
5
|
+
//keep these literal. otherwise the test loses value as a test.
|
6
|
+
function green(str) { return '\033[32m' + str + '\033[0m'; }
|
7
|
+
function red(str) { return '\033[31m' + str + '\033[0m'; }
|
8
|
+
function yellow(str) { return '\033[33m' + str + '\033[0m'; }
|
9
|
+
|
10
|
+
function prefixGreen(str) { return '\033[32m' + str; }
|
11
|
+
function prefixRed(str) { return '\033[31m' + str; }
|
12
|
+
|
13
|
+
var newline = "\n";
|
14
|
+
|
15
|
+
var passingSpec = { results: function(){ return {passed: function(){return true;}}; } },
|
16
|
+
failingSpec = { results: function(){ return {passed: function(){return false;}}; } },
|
17
|
+
skippedSpec = { results: function(){ return {skipped: true}; } },
|
18
|
+
passingRun = { results: function(){ return {failedCount: 0, items_: [null, null, null]}; } },
|
19
|
+
failingRun = { results: function(){ return {failedCount: 7, items_: [null, null, null]}; } };
|
20
|
+
|
21
|
+
function repeatedlyInvoke(f, times) { for(var i=0; i<times; i++) f(times+1); }
|
22
|
+
|
23
|
+
function repeat(thing, times) {
|
24
|
+
var arr = [];
|
25
|
+
for(var i=0; i<times; i++) arr.push(thing);
|
26
|
+
return arr;
|
27
|
+
}
|
28
|
+
|
29
|
+
var fiftyRedFs = repeat(red("F"), 50).join(""),
|
30
|
+
fiftyGreenDots = repeat(green("."), 50).join("");
|
31
|
+
|
32
|
+
function simulateRun(reporter, specResults, suiteResults, finalRunner, startTime, endTime) {
|
33
|
+
reporter.reportRunnerStarting();
|
34
|
+
for(var i=0; i<specResults.length; i++) reporter.reportSpecResults(specResults[i]);
|
35
|
+
for(i=0; i<suiteResults.length; i++) reporter.reportSuiteResults(suiteResults[i]);
|
36
|
+
reporter.runnerStartTime = startTime;
|
37
|
+
reporter.now = function(){return endTime;};
|
38
|
+
reporter.reportRunnerResults(finalRunner);
|
39
|
+
}
|
40
|
+
|
41
|
+
beforeEach(function() {
|
42
|
+
this.out = (function(){
|
43
|
+
var output = "";
|
44
|
+
return {
|
45
|
+
print:function(str) {output += str;},
|
46
|
+
getOutput:function(){return output;},
|
47
|
+
clear: function(){output = "";}
|
48
|
+
};
|
49
|
+
})();
|
50
|
+
|
51
|
+
this.done = false
|
52
|
+
var self = this
|
53
|
+
this.reporter = new jasmine.TrivialConsoleReporter(this.out.print, function(runner){
|
54
|
+
self.done = true
|
55
|
+
});
|
56
|
+
});
|
57
|
+
|
58
|
+
|
59
|
+
describe('Integration', function(){
|
60
|
+
it("prints the proper output under a pass scenario. small numbers.", function(){
|
61
|
+
simulateRun(this.reporter,
|
62
|
+
repeat(passingSpec, 3),
|
63
|
+
[],
|
64
|
+
{
|
65
|
+
results:function(){
|
66
|
+
return {
|
67
|
+
items_: [null, null, null],
|
68
|
+
totalCount: 7,
|
69
|
+
failedCount: 0
|
70
|
+
};
|
71
|
+
}
|
72
|
+
},
|
73
|
+
1000,
|
74
|
+
1777);
|
75
|
+
|
76
|
+
expect(this.out.getOutput()).toEqual(
|
77
|
+
[
|
78
|
+
"Started",
|
79
|
+
green(".") + green(".") + green("."),
|
80
|
+
"",
|
81
|
+
"Finished in 0.777 seconds",
|
82
|
+
green("3 specs, 7 expectations, 0 failures"),
|
83
|
+
""
|
84
|
+
].join("\n") + "\n"
|
85
|
+
);
|
86
|
+
});
|
87
|
+
|
88
|
+
it("prints the proper output under a pass scenario. large numbers.", function(){
|
89
|
+
simulateRun(this.reporter,
|
90
|
+
repeat(passingSpec, 57),
|
91
|
+
[],
|
92
|
+
{
|
93
|
+
results:function(){
|
94
|
+
return {
|
95
|
+
items_: [null, null, null],
|
96
|
+
totalCount: 7,
|
97
|
+
failedCount: 0
|
98
|
+
};
|
99
|
+
}
|
100
|
+
},
|
101
|
+
1000,
|
102
|
+
1777);
|
103
|
+
|
104
|
+
expect(this.out.getOutput()).toEqual(
|
105
|
+
[
|
106
|
+
"Started",
|
107
|
+
|
108
|
+
green(".") + green(".") + green(".") + green(".") + green(".") + //50 green dots
|
109
|
+
green(".") + green(".") + green(".") + green(".") + green(".") +
|
110
|
+
green(".") + green(".") + green(".") + green(".") + green(".") +
|
111
|
+
green(".") + green(".") + green(".") + green(".") + green(".") +
|
112
|
+
green(".") + green(".") + green(".") + green(".") + green(".") +
|
113
|
+
green(".") + green(".") + green(".") + green(".") + green(".") +
|
114
|
+
green(".") + green(".") + green(".") + green(".") + green(".") +
|
115
|
+
green(".") + green(".") + green(".") + green(".") + green(".") +
|
116
|
+
green(".") + green(".") + green(".") + green(".") + green(".") +
|
117
|
+
green(".") + green(".") + green(".") + green(".") + green(".") + newline +
|
118
|
+
|
119
|
+
green(".") + green(".") + green(".") + green(".") + green(".") + //7 green dots
|
120
|
+
green(".") + green("."),
|
121
|
+
|
122
|
+
"",
|
123
|
+
"Finished in 0.777 seconds",
|
124
|
+
green("3 specs, 7 expectations, 0 failures"),
|
125
|
+
""
|
126
|
+
].join("\n") + "\n"
|
127
|
+
);
|
128
|
+
});
|
129
|
+
|
130
|
+
|
131
|
+
it("prints the proper output under a failure scenario.", function(){
|
132
|
+
simulateRun(this.reporter,
|
133
|
+
[failingSpec, passingSpec, failingSpec],
|
134
|
+
[{description:"The oven",
|
135
|
+
results:function(){
|
136
|
+
return {
|
137
|
+
items_:[
|
138
|
+
{failedCount:2,
|
139
|
+
description:"heats up",
|
140
|
+
items_:[
|
141
|
+
{trace:{stack:"stack trace one\n second line"}},
|
142
|
+
{trace:{stack:"stack trace two"}}
|
143
|
+
]}
|
144
|
+
]
|
145
|
+
};
|
146
|
+
}},
|
147
|
+
{description:"The washing machine",
|
148
|
+
results:function(){
|
149
|
+
return {
|
150
|
+
items_:[
|
151
|
+
{failedCount:2,
|
152
|
+
description:"washes clothes",
|
153
|
+
items_:[
|
154
|
+
{trace:{stack:"stack trace one"}}
|
155
|
+
]}
|
156
|
+
]
|
157
|
+
};
|
158
|
+
}}
|
159
|
+
],
|
160
|
+
{
|
161
|
+
results:function(){
|
162
|
+
return {
|
163
|
+
items_: [null, null, null],
|
164
|
+
totalCount: 7,
|
165
|
+
failedCount: 2
|
166
|
+
};
|
167
|
+
}
|
168
|
+
},
|
169
|
+
1000,
|
170
|
+
1777);
|
171
|
+
|
172
|
+
expect(this.out.getOutput()).toEqual(
|
173
|
+
[
|
174
|
+
"Started",
|
175
|
+
red("F") + green(".") + red("F"),
|
176
|
+
"",
|
177
|
+
"The oven heats up",
|
178
|
+
" stack trace one",
|
179
|
+
" second line",
|
180
|
+
" stack trace two",
|
181
|
+
"",
|
182
|
+
"The washing machine washes clothes",
|
183
|
+
" stack trace one",
|
184
|
+
"",
|
185
|
+
"Finished in 0.777 seconds",
|
186
|
+
red("3 specs, 7 expectations, 2 failures"),
|
187
|
+
""
|
188
|
+
].join("\n") + "\n"
|
189
|
+
);
|
190
|
+
});
|
191
|
+
|
192
|
+
|
193
|
+
});
|
194
|
+
|
195
|
+
describe('A Test Run', function(){
|
196
|
+
|
197
|
+
describe('Starts', function(){
|
198
|
+
it("prints Started", function(){
|
199
|
+
this.reporter.reportRunnerStarting();
|
200
|
+
|
201
|
+
expect(this.out.getOutput()).toEqual(
|
202
|
+
"Started" + newline
|
203
|
+
);
|
204
|
+
});
|
205
|
+
});
|
206
|
+
|
207
|
+
describe('A spec runs', function(){
|
208
|
+
it("prints a green dot if the spec passes", function(){
|
209
|
+
this.reporter.reportSpecResults(passingSpec);
|
210
|
+
|
211
|
+
expect(this.out.getOutput()).toEqual(
|
212
|
+
green(".")
|
213
|
+
);
|
214
|
+
});
|
215
|
+
|
216
|
+
it("prints a red dot if the spec fails", function(){
|
217
|
+
this.reporter.reportSpecResults(failingSpec);
|
218
|
+
|
219
|
+
expect(this.out.getOutput()).toEqual(
|
220
|
+
red("F")
|
221
|
+
);
|
222
|
+
});
|
223
|
+
|
224
|
+
it("prints a yellow star if the spec was skipped", function(){
|
225
|
+
this.reporter.reportSpecResults(skippedSpec);
|
226
|
+
|
227
|
+
expect(this.out.getOutput()).toEqual(
|
228
|
+
yellow("*")
|
229
|
+
);
|
230
|
+
});
|
231
|
+
});
|
232
|
+
|
233
|
+
|
234
|
+
describe('Many specs run', function(){
|
235
|
+
it("starts a new line every 50 specs", function(){
|
236
|
+
var self = this;
|
237
|
+
repeatedlyInvoke(function(){self.reporter.reportSpecResults(failingSpec);}, 49);
|
238
|
+
|
239
|
+
expect(this.out.getOutput()).
|
240
|
+
toEqual(repeat(red("F"), 49).join(""));
|
241
|
+
|
242
|
+
repeatedlyInvoke(function(){self.reporter.reportSpecResults(failingSpec);}, 3);
|
243
|
+
|
244
|
+
expect(this.out.getOutput()).
|
245
|
+
toEqual(fiftyRedFs + newline +
|
246
|
+
red("F") + red("F"));
|
247
|
+
|
248
|
+
repeatedlyInvoke(function(){self.reporter.reportSpecResults(failingSpec);}, 48);
|
249
|
+
repeatedlyInvoke(function(){self.reporter.reportSpecResults(passingSpec);}, 2);
|
250
|
+
|
251
|
+
expect(this.out.getOutput()).
|
252
|
+
toEqual(fiftyRedFs + newline +
|
253
|
+
fiftyRedFs + newline +
|
254
|
+
green(".") + green("."));
|
255
|
+
});
|
256
|
+
});
|
257
|
+
|
258
|
+
describe('A suite runs', function(){
|
259
|
+
it("remembers suite results", function(){
|
260
|
+
var emptyResults = function(){return {items_:[]};};
|
261
|
+
this.reporter.reportSuiteResults({description:"Oven", results:emptyResults});
|
262
|
+
this.reporter.reportSuiteResults({description:"Mixer", results:emptyResults});
|
263
|
+
|
264
|
+
var self = this;
|
265
|
+
var descriptions = [];
|
266
|
+
for(var i=0; i<self.reporter.suiteResults.length; i++)
|
267
|
+
descriptions.push(self.reporter.suiteResults[i].description);
|
268
|
+
|
269
|
+
expect(descriptions).toEqual(["Oven", "Mixer"]);
|
270
|
+
});
|
271
|
+
|
272
|
+
it("creates a description out of the current suite and any parent suites", function(){
|
273
|
+
var emptyResults = function(){return {items_:[]};};
|
274
|
+
var grandparentSuite = {description:"My house", results:emptyResults};
|
275
|
+
var parentSuite = {description:"kitchen", parentSuite: grandparentSuite, results:emptyResults};
|
276
|
+
this.reporter.reportSuiteResults({description:"oven", parentSuite: parentSuite, results:emptyResults});
|
277
|
+
|
278
|
+
expect(this.reporter.suiteResults[0].description).toEqual("My house kitchen oven");
|
279
|
+
});
|
280
|
+
|
281
|
+
it("gathers failing spec results from the suite. the spec must have a description.", function(){
|
282
|
+
this.reporter.reportSuiteResults({description:"Oven",
|
283
|
+
results:function(){
|
284
|
+
return {
|
285
|
+
items_:[
|
286
|
+
{failedCount:0, description:"specOne"},
|
287
|
+
{failedCount:99, description:"specTwo"},
|
288
|
+
{failedCount:0, description:"specThree"},
|
289
|
+
{failedCount:88, description:"specFour"},
|
290
|
+
{failedCount:3}
|
291
|
+
]
|
292
|
+
};
|
293
|
+
}});
|
294
|
+
|
295
|
+
expect(this.reporter.suiteResults[0].failedSpecResults).
|
296
|
+
toEqual([
|
297
|
+
{failedCount:99, description:"specTwo"},
|
298
|
+
{failedCount:88, description:"specFour"}
|
299
|
+
]);
|
300
|
+
});
|
301
|
+
|
302
|
+
});
|
303
|
+
|
304
|
+
describe('Finishes', function(){
|
305
|
+
|
306
|
+
describe('Spec failure information', function(){
|
307
|
+
|
308
|
+
it("prints suite and spec descriptions together as a sentence", function(){
|
309
|
+
this.reporter.suiteResults = [
|
310
|
+
{description:"The oven", failedSpecResults:[
|
311
|
+
{description:"heats up", items_:[]},
|
312
|
+
{description:"cleans itself", items_:[]}
|
313
|
+
]},
|
314
|
+
{description:"The mixer", failedSpecResults:[
|
315
|
+
{description:"blends things together", items_:[]}
|
316
|
+
]}
|
317
|
+
];
|
318
|
+
|
319
|
+
this.reporter.reportRunnerResults(failingRun);
|
320
|
+
|
321
|
+
expect(this.out.getOutput()).toContain("The oven heats up");
|
322
|
+
expect(this.out.getOutput()).toContain("The oven cleans itself");
|
323
|
+
expect(this.out.getOutput()).toContain("The mixer blends things together");
|
324
|
+
});
|
325
|
+
|
326
|
+
it("prints stack trace of spec failure", function(){
|
327
|
+
this.reporter.suiteResults = [
|
328
|
+
{description:"The oven", failedSpecResults:[
|
329
|
+
{description:"heats up",
|
330
|
+
items_:[
|
331
|
+
{trace:{stack:"stack trace one"}},
|
332
|
+
{trace:{stack:"stack trace two"}}
|
333
|
+
]}
|
334
|
+
]}
|
335
|
+
];
|
336
|
+
|
337
|
+
this.reporter.reportRunnerResults(failingRun);
|
338
|
+
|
339
|
+
expect(this.out.getOutput()).toContain("The oven heats up");
|
340
|
+
expect(this.out.getOutput()).toContain("stack trace one");
|
341
|
+
expect(this.out.getOutput()).toContain("stack trace two");
|
342
|
+
});
|
343
|
+
|
344
|
+
});
|
345
|
+
|
346
|
+
describe('Finished line', function(){
|
347
|
+
|
348
|
+
it("prints the elapsed time in the summary message", function(){
|
349
|
+
this.reporter.now = function(){return 1000;};
|
350
|
+
this.reporter.reportRunnerStarting();
|
351
|
+
this.reporter.now = function(){return 1777;};
|
352
|
+
this.reporter.reportRunnerResults(passingRun);
|
353
|
+
expect(this.out.getOutput()).toContain("0.777 seconds");
|
354
|
+
});
|
355
|
+
|
356
|
+
it("prints round time numbers correctly", function(){
|
357
|
+
var self = this;
|
358
|
+
function run(startTime, endTime) {
|
359
|
+
self.out.clear();
|
360
|
+
self.reporter.runnerStartTime = startTime;
|
361
|
+
self.reporter.now = function(){return endTime;};
|
362
|
+
self.reporter.reportRunnerResults(passingRun);
|
363
|
+
}
|
364
|
+
|
365
|
+
run(1000, 11000);
|
366
|
+
expect(this.out.getOutput()).toContain("10 seconds");
|
367
|
+
|
368
|
+
run(1000, 2000);
|
369
|
+
expect(this.out.getOutput()).toContain("1 seconds");
|
370
|
+
|
371
|
+
run(1000, 1100);
|
372
|
+
expect(this.out.getOutput()).toContain("0.1 seconds");
|
373
|
+
|
374
|
+
run(1000, 1010);
|
375
|
+
expect(this.out.getOutput()).toContain("0.01 seconds");
|
376
|
+
|
377
|
+
run(1000, 1001);
|
378
|
+
expect(this.out.getOutput()).toContain("0.001 seconds");
|
379
|
+
});
|
380
|
+
|
381
|
+
it("prints the full finished message", function(){
|
382
|
+
this.reporter.now = function(){return 1000;};
|
383
|
+
this.reporter.reportRunnerStarting();
|
384
|
+
this.reporter.now = function(){return 1777;};
|
385
|
+
this.reporter.reportRunnerResults(failingRun);
|
386
|
+
expect(this.out.getOutput()).toContain("Finished in 0.777 seconds");
|
387
|
+
});
|
388
|
+
});
|
389
|
+
|
390
|
+
describe("specs/expectations/failures summary", function(){
|
391
|
+
it("prints statistics in green if there were no failures", function() {
|
392
|
+
this.reporter.reportRunnerResults({
|
393
|
+
results:function(){return {items_: [null, null, null], totalCount: 7, failedCount: 0};}
|
394
|
+
});
|
395
|
+
expect(this.out.getOutput()).
|
396
|
+
toContain("3 specs, 7 expectations, 0 failures");
|
397
|
+
});
|
398
|
+
|
399
|
+
it("prints statistics in red if there was a failure", function() {
|
400
|
+
this.reporter.reportRunnerResults({
|
401
|
+
results:function(){return {items_: [null, null, null], totalCount: 7, failedCount: 3};}
|
402
|
+
});
|
403
|
+
expect(this.out.getOutput()).
|
404
|
+
toContain("3 specs, 7 expectations, 3 failures");
|
405
|
+
});
|
406
|
+
|
407
|
+
it("handles pluralization with 1's ones appropriately", function() {
|
408
|
+
this.reporter.reportRunnerResults({
|
409
|
+
results:function(){return {items_: [null], totalCount: 1, failedCount: 1};}
|
410
|
+
});
|
411
|
+
expect(this.out.getOutput()).
|
412
|
+
toContain("1 spec, 1 expectation, 1 failure");
|
413
|
+
});
|
414
|
+
});
|
415
|
+
|
416
|
+
describe("done callback", function(){
|
417
|
+
it("calls back when done", function() {
|
418
|
+
expect(this.done).toBeFalsy();
|
419
|
+
this.reporter.reportRunnerResults({
|
420
|
+
results:function(){return {items_: [null, null, null], totalCount: 7, failedCount: 0};}
|
421
|
+
});
|
422
|
+
expect(this.done).toBeTruthy();
|
423
|
+
});
|
424
|
+
});
|
425
|
+
|
426
|
+
});
|
427
|
+
|
428
|
+
});
|
429
|
+
|
430
|
+
});
|
431
|
+
}
|
@@ -0,0 +1,238 @@
|
|
1
|
+
describe("TrivialReporter", function() {
|
2
|
+
var env;
|
3
|
+
var trivialReporter;
|
4
|
+
var body;
|
5
|
+
var fakeDocument;
|
6
|
+
|
7
|
+
beforeEach(function() {
|
8
|
+
env = new jasmine.Env();
|
9
|
+
env.updateInterval = 0;
|
10
|
+
|
11
|
+
body = document.createElement("body");
|
12
|
+
fakeDocument = { body: body, location: { search: "" } };
|
13
|
+
trivialReporter = new jasmine.TrivialReporter(fakeDocument);
|
14
|
+
});
|
15
|
+
|
16
|
+
function fakeSpec(name) {
|
17
|
+
return {
|
18
|
+
getFullName: function() {
|
19
|
+
return name;
|
20
|
+
}
|
21
|
+
};
|
22
|
+
}
|
23
|
+
|
24
|
+
function findElements(divs, withClass) {
|
25
|
+
var els = [];
|
26
|
+
for (var i = 0; i < divs.length; i++) {
|
27
|
+
if (divs[i].className == withClass) els.push(divs[i]);
|
28
|
+
}
|
29
|
+
return els;
|
30
|
+
}
|
31
|
+
|
32
|
+
function findElement(divs, withClass) {
|
33
|
+
var els = findElements(divs, withClass);
|
34
|
+
if (els.length > 0) return els[0];
|
35
|
+
throw new Error("couldn't find div with class " + withClass);
|
36
|
+
}
|
37
|
+
|
38
|
+
it("should run only specs beginning with spec parameter", function() {
|
39
|
+
fakeDocument.location.search = "?spec=run%20this";
|
40
|
+
expect(trivialReporter.specFilter(fakeSpec("run this"))).toBeTruthy();
|
41
|
+
expect(trivialReporter.specFilter(fakeSpec("not the right spec"))).toBeFalsy();
|
42
|
+
expect(trivialReporter.specFilter(fakeSpec("not run this"))).toBeFalsy();
|
43
|
+
});
|
44
|
+
|
45
|
+
it("should display empty divs for every suite when the runner is starting", function() {
|
46
|
+
trivialReporter.reportRunnerStarting({
|
47
|
+
env: env,
|
48
|
+
suites: function() {
|
49
|
+
return [ new jasmine.Suite({}, "suite 1", null, null) ];
|
50
|
+
}
|
51
|
+
});
|
52
|
+
|
53
|
+
var divs = findElements(body.getElementsByTagName("div"), "suite");
|
54
|
+
expect(divs.length).toEqual(1);
|
55
|
+
expect(divs[0].innerHTML).toContain("suite 1");
|
56
|
+
});
|
57
|
+
|
58
|
+
describe('Matcher reporting', function () {
|
59
|
+
var getResultMessageDiv = function (body) {
|
60
|
+
var divs = body.getElementsByTagName("div");
|
61
|
+
for (var i = 0; i < divs.length; i++) {
|
62
|
+
if (divs[i].className.match(/resultMessage/)) {
|
63
|
+
return divs[i];
|
64
|
+
}
|
65
|
+
}
|
66
|
+
};
|
67
|
+
|
68
|
+
var runner, spec, fakeTimer;
|
69
|
+
beforeEach(function () {
|
70
|
+
fakeTimer = new jasmine.FakeTimer();
|
71
|
+
env.setTimeout = fakeTimer.setTimeout;
|
72
|
+
env.clearTimeout = fakeTimer.clearTimeout;
|
73
|
+
env.setInterval = fakeTimer.setInterval;
|
74
|
+
env.clearInterval = fakeTimer.clearInterval;
|
75
|
+
runner = env.currentRunner();
|
76
|
+
var suite = new jasmine.Suite(env, 'some suite');
|
77
|
+
runner.add(suite);
|
78
|
+
spec = new jasmine.Spec(env, suite, 'some spec');
|
79
|
+
suite.add(spec);
|
80
|
+
fakeDocument.location.search = "?";
|
81
|
+
env.addReporter(trivialReporter);
|
82
|
+
});
|
83
|
+
|
84
|
+
describe('toContain', function () {
|
85
|
+
it('should show actual and expected', function () {
|
86
|
+
spec.runs(function () {
|
87
|
+
this.expect('foo').toContain('bar');
|
88
|
+
});
|
89
|
+
runner.execute();
|
90
|
+
fakeTimer.tick(0);
|
91
|
+
|
92
|
+
var resultEl = getResultMessageDiv(body);
|
93
|
+
expect(resultEl.innerHTML).toMatch(/foo/);
|
94
|
+
expect(resultEl.innerHTML).toMatch(/bar/);
|
95
|
+
});
|
96
|
+
});
|
97
|
+
});
|
98
|
+
|
99
|
+
|
100
|
+
describe("failure messages (integration)", function () {
|
101
|
+
var spec, results, expectationResult;
|
102
|
+
|
103
|
+
beforeEach(function() {
|
104
|
+
results = {
|
105
|
+
passed: function() {
|
106
|
+
return false;
|
107
|
+
},
|
108
|
+
getItems: function() {
|
109
|
+
}};
|
110
|
+
|
111
|
+
var suite1 = new jasmine.Suite(env, "suite 1", null, null);
|
112
|
+
|
113
|
+
spec = {
|
114
|
+
suite: suite1,
|
115
|
+
getFullName: function() {
|
116
|
+
return "foo";
|
117
|
+
},
|
118
|
+
results: function() {
|
119
|
+
return results;
|
120
|
+
}
|
121
|
+
};
|
122
|
+
|
123
|
+
trivialReporter.reportRunnerStarting({
|
124
|
+
env: env,
|
125
|
+
suites: function() {
|
126
|
+
return [ suite1 ];
|
127
|
+
}
|
128
|
+
});
|
129
|
+
});
|
130
|
+
|
131
|
+
it("should add the failure message to the DOM (non-toEquals matchers)", function() {
|
132
|
+
expectationResult = new jasmine.ExpectationResult({
|
133
|
+
matcherName: "toBeNull", passed: false, message: "Expected 'a' to be null, but it was not"
|
134
|
+
});
|
135
|
+
|
136
|
+
spyOn(results, 'getItems').andReturn([expectationResult]);
|
137
|
+
|
138
|
+
trivialReporter.reportSpecResults(spec);
|
139
|
+
|
140
|
+
var divs = body.getElementsByTagName("div");
|
141
|
+
var errorDiv = findElement(divs, 'resultMessage fail');
|
142
|
+
expect(errorDiv.innerHTML).toEqual("Expected 'a' to be null, but it was not");
|
143
|
+
});
|
144
|
+
|
145
|
+
it("should add the failure message to the DOM (non-toEquals matchers) html escaping", function() {
|
146
|
+
expectationResult = new jasmine.ExpectationResult({
|
147
|
+
matcherName: "toBeNull", passed: false, message: "Expected '1 < 2' to <b>e null, & it was not"
|
148
|
+
});
|
149
|
+
|
150
|
+
spyOn(results, 'getItems').andReturn([expectationResult]);
|
151
|
+
|
152
|
+
trivialReporter.reportSpecResults(spec);
|
153
|
+
|
154
|
+
var divs = body.getElementsByTagName("div");
|
155
|
+
var errorDiv = findElement(divs, 'resultMessage fail');
|
156
|
+
expect(errorDiv.innerHTML).toEqual("Expected '1 < 2' to <b>e null, & it was not");
|
157
|
+
});
|
158
|
+
});
|
159
|
+
|
160
|
+
describe("log messages", function() {
|
161
|
+
it("should appear in the report", function() {
|
162
|
+
env.describe("suite", function() {
|
163
|
+
env.it("will have log messages", function() {
|
164
|
+
this.log("this is a", "multipart log message");
|
165
|
+
});
|
166
|
+
});
|
167
|
+
|
168
|
+
env.addReporter(trivialReporter);
|
169
|
+
env.execute();
|
170
|
+
|
171
|
+
var divs = body.getElementsByTagName("div");
|
172
|
+
var errorDiv = findElement(divs, 'resultMessage log');
|
173
|
+
expect(errorDiv.innerHTML).toEqual("this is a multipart log message");
|
174
|
+
});
|
175
|
+
|
176
|
+
xit("should work on IE without console.log.apply", function() {
|
177
|
+
});
|
178
|
+
});
|
179
|
+
|
180
|
+
describe("duplicate example names", function() {
|
181
|
+
it("should report failures correctly", function() {
|
182
|
+
var suite1 = env.describe("suite", function() {
|
183
|
+
env.it("will have log messages", function() {
|
184
|
+
this.log("this one fails!");
|
185
|
+
this.expect(true).toBeFalsy();
|
186
|
+
});
|
187
|
+
});
|
188
|
+
|
189
|
+
var suite2 = env.describe("suite", function() {
|
190
|
+
env.it("will have log messages", function() {
|
191
|
+
this.log("this one passes!");
|
192
|
+
this.expect(true).toBeTruthy();
|
193
|
+
});
|
194
|
+
});
|
195
|
+
|
196
|
+
env.addReporter(trivialReporter);
|
197
|
+
env.execute();
|
198
|
+
|
199
|
+
var divs = body.getElementsByTagName("div");
|
200
|
+
var passedSpecDiv = findElement(divs, 'suite passed');
|
201
|
+
expect(passedSpecDiv.className).toEqual('suite passed');
|
202
|
+
expect(passedSpecDiv.innerHTML).toContain("this one passes!");
|
203
|
+
expect(passedSpecDiv.innerHTML).not.toContain("this one fails!");
|
204
|
+
|
205
|
+
var failedSpecDiv = findElement(divs, 'suite failed');
|
206
|
+
expect(failedSpecDiv.className).toEqual('suite failed');
|
207
|
+
expect(failedSpecDiv.innerHTML).toContain("this one fails!");
|
208
|
+
expect(failedSpecDiv.innerHTML).not.toContain("this one passes!");
|
209
|
+
});
|
210
|
+
});
|
211
|
+
|
212
|
+
describe('#reportSpecStarting', function() {
|
213
|
+
var spec1;
|
214
|
+
beforeEach(function () {
|
215
|
+
env.describe("suite 1", function() {
|
216
|
+
spec1 = env.it("spec 1", function() {
|
217
|
+
});
|
218
|
+
});
|
219
|
+
});
|
220
|
+
|
221
|
+
it('DOES NOT log running specs by default', function() {
|
222
|
+
spyOn(trivialReporter, 'log');
|
223
|
+
|
224
|
+
trivialReporter.reportSpecStarting(spec1);
|
225
|
+
|
226
|
+
expect(trivialReporter.log).not.toHaveBeenCalled();
|
227
|
+
});
|
228
|
+
|
229
|
+
it('logs running specs when log_running_specs is true', function() {
|
230
|
+
trivialReporter.logRunningSpecs = true;
|
231
|
+
spyOn(trivialReporter, 'log');
|
232
|
+
|
233
|
+
trivialReporter.reportSpecStarting(spec1);
|
234
|
+
|
235
|
+
expect(trivialReporter.log).toHaveBeenCalledWith('>> Jasmine Running suite 1 spec 1...');
|
236
|
+
});
|
237
|
+
});
|
238
|
+
});
|