jasnode 0.2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (129) hide show
  1. data/.gitignore +1 -0
  2. data/.gitmodules +3 -0
  3. data/MIT.LICENSE +20 -0
  4. data/README.md +28 -0
  5. data/Rakefile +34 -0
  6. data/VERSION.yml +5 -0
  7. data/bin/jasnode +52 -0
  8. data/features/jasnode.feature +24 -0
  9. data/features/step_definitions/jasnode-steps.rb +39 -0
  10. data/jasmine/MIT.LICENSE +20 -0
  11. data/jasmine/README.markdown +502 -0
  12. data/jasmine/Rakefile +158 -0
  13. data/jasmine/cruise_config.rb +21 -0
  14. data/jasmine/doc/files.html +460 -0
  15. data/jasmine/doc/index.html +322 -0
  16. data/jasmine/doc/symbols/_global_.html +918 -0
  17. data/jasmine/doc/symbols/jasmine.Block.html +417 -0
  18. data/jasmine/doc/symbols/jasmine.Clock.html +678 -0
  19. data/jasmine/doc/symbols/jasmine.Env.html +1169 -0
  20. data/jasmine/doc/symbols/jasmine.JsApiReporter.html +822 -0
  21. data/jasmine/doc/symbols/jasmine.Matchers.html +1474 -0
  22. data/jasmine/doc/symbols/jasmine.MultiReporter.html +394 -0
  23. data/jasmine/doc/symbols/jasmine.NestedResults.html +710 -0
  24. data/jasmine/doc/symbols/jasmine.Reporter.html +574 -0
  25. data/jasmine/doc/symbols/jasmine.Runner.html +710 -0
  26. data/jasmine/doc/symbols/jasmine.Spec.html +1253 -0
  27. data/jasmine/doc/symbols/jasmine.Spy.html +855 -0
  28. data/jasmine/doc/symbols/jasmine.Suite.html +705 -0
  29. data/jasmine/doc/symbols/jasmine.html +1345 -0
  30. data/jasmine/doc/symbols/jasmine.util.html +535 -0
  31. data/jasmine/doc/symbols/src/lib_TrivialReporter.js.html +124 -0
  32. data/jasmine/doc/symbols/src/src_Block.js.html +29 -0
  33. data/jasmine/doc/symbols/src/src_Env.js.html +248 -0
  34. data/jasmine/doc/symbols/src/src_JsApiReporter.js.html +111 -0
  35. data/jasmine/doc/symbols/src/src_Matchers.js.html +344 -0
  36. data/jasmine/doc/symbols/src/src_MultiReporter.js.html +36 -0
  37. data/jasmine/doc/symbols/src/src_NestedResults.js.html +88 -0
  38. data/jasmine/doc/symbols/src/src_PrettyPrinter.js.html +130 -0
  39. data/jasmine/doc/symbols/src/src_Queue.js.html +102 -0
  40. data/jasmine/doc/symbols/src/src_Reporter.js.html +35 -0
  41. data/jasmine/doc/symbols/src/src_Reporters.js.html +51 -0
  42. data/jasmine/doc/symbols/src/src_Runner.js.html +75 -0
  43. data/jasmine/doc/symbols/src/src_Spec.js.html +214 -0
  44. data/jasmine/doc/symbols/src/src_Suite.js.html +77 -0
  45. data/jasmine/doc/symbols/src/src_WaitsBlock.js.html +21 -0
  46. data/jasmine/doc/symbols/src/src_WaitsForBlock.js.html +45 -0
  47. data/jasmine/doc/symbols/src/src_base.js.html +585 -0
  48. data/jasmine/doc/symbols/src/src_mock-timeout.js.html +185 -0
  49. data/jasmine/doc/symbols/src/src_util.js.html +75 -0
  50. data/jasmine/examples/html/example_runner.html +27 -0
  51. data/jasmine/examples/html/spec/example_suite.js +11 -0
  52. data/jasmine/examples/ruby/Rakefile +33 -0
  53. data/jasmine/examples/ruby/spec/example/example_spec.js +11 -0
  54. data/jasmine/examples/ruby/spec/jasmine_helper.rb +41 -0
  55. data/jasmine/examples/ruby/spec/jasmine_spec.rb +31 -0
  56. data/jasmine/examples/ruby/spec/saucelabs.yml +24 -0
  57. data/jasmine/geminstaller.yml +25 -0
  58. data/jasmine/images/fail-16.png +0 -0
  59. data/jasmine/images/fail.png +0 -0
  60. data/jasmine/images/go-16.png +0 -0
  61. data/jasmine/images/go.png +0 -0
  62. data/jasmine/images/pending-16.png +0 -0
  63. data/jasmine/images/pending.png +0 -0
  64. data/jasmine/images/question-bk.png +0 -0
  65. data/jasmine/images/questionbk-16.png +0 -0
  66. data/jasmine/images/spinner.gif +0 -0
  67. data/jasmine/lib/TrivialReporter.js +117 -0
  68. data/jasmine/lib/consolex.js +28 -0
  69. data/jasmine/lib/jasmine-0.10.2.js +2318 -0
  70. data/jasmine/lib/jasmine.css +86 -0
  71. data/jasmine/lib/json2.js +478 -0
  72. data/jasmine/spec/jasmine_helper.rb +44 -0
  73. data/jasmine/spec/jasmine_spec.rb +31 -0
  74. data/jasmine/spec/runner.html +79 -0
  75. data/jasmine/spec/saucelabs.yml +24 -0
  76. data/jasmine/spec/suites/CustomMatchersSpec.js +112 -0
  77. data/jasmine/spec/suites/EnvSpec.js +141 -0
  78. data/jasmine/spec/suites/ExceptionsSpec.js +107 -0
  79. data/jasmine/spec/suites/JsApiReporterSpec.js +82 -0
  80. data/jasmine/spec/suites/MatchersSpec.js +709 -0
  81. data/jasmine/spec/suites/MockClockSpec.js +34 -0
  82. data/jasmine/spec/suites/MultiReporterSpec.js +30 -0
  83. data/jasmine/spec/suites/NestedResultsSpec.js +54 -0
  84. data/jasmine/spec/suites/PrettyPrintSpec.js +93 -0
  85. data/jasmine/spec/suites/QueueSpec.js +23 -0
  86. data/jasmine/spec/suites/ReporterSpec.js +60 -0
  87. data/jasmine/spec/suites/RunnerSpec.js +252 -0
  88. data/jasmine/spec/suites/SpecRunningSpec.js +1086 -0
  89. data/jasmine/spec/suites/SpecSpec.js +110 -0
  90. data/jasmine/spec/suites/SpySpec.js +201 -0
  91. data/jasmine/spec/suites/SuiteSpec.js +101 -0
  92. data/jasmine/spec/suites/TrivialReporterSpec.js +140 -0
  93. data/jasmine/spec/suites/UtilSpec.js +40 -0
  94. data/jasmine/src/Block.js +22 -0
  95. data/jasmine/src/Env.js +240 -0
  96. data/jasmine/src/JsApiReporter.js +103 -0
  97. data/jasmine/src/Matchers.js +336 -0
  98. data/jasmine/src/MultiReporter.js +28 -0
  99. data/jasmine/src/NestedResults.js +80 -0
  100. data/jasmine/src/PrettyPrinter.js +122 -0
  101. data/jasmine/src/Queue.js +94 -0
  102. data/jasmine/src/Reporter.js +27 -0
  103. data/jasmine/src/Reporters.js +43 -0
  104. data/jasmine/src/Runner.js +68 -0
  105. data/jasmine/src/Spec.js +206 -0
  106. data/jasmine/src/Suite.js +70 -0
  107. data/jasmine/src/WaitsBlock.js +13 -0
  108. data/jasmine/src/WaitsForBlock.js +38 -0
  109. data/jasmine/src/base.js +578 -0
  110. data/jasmine/src/mock-timeout.js +177 -0
  111. data/jasmine/src/util.js +67 -0
  112. data/jasmine/src/version.json +5 -0
  113. data/jasnode.gemspec +171 -0
  114. data/lib/jasnode/core.rb +180 -0
  115. data/lib/jasnode.js +135 -0
  116. data/lib/jasnode.rb +4 -0
  117. data/pkg/jasnode-0.1.0.0.gem +0 -0
  118. data/spec/jasnode/jasnode_spec.rb +40 -0
  119. data/spec/rspec_suite.rb +8 -0
  120. data/spec/spec_helper.rb +6 -0
  121. data/templates/Rakefile +9 -0
  122. data/templates/bin/hello_world +5 -0
  123. data/templates/lib/server.js +25 -0
  124. data/templates/spec/README.md +3 -0
  125. data/templates/spec/runner.js +16 -0
  126. data/templates/spec/server/server_spec.js +45 -0
  127. data/templates/spec/server/spec_server.js +45 -0
  128. data/templates/spec/spec.js +45 -0
  129. metadata +184 -0
@@ -0,0 +1,502 @@
1
+ Jasmine
2
+ =======
3
+ **A JavaScript Testing Framework**
4
+
5
+ Quick Start
6
+ ----------
7
+
8
+ ### Ruby Suite Running
9
+
10
+ Please use the [jasmine-ruby gem](http://github.com/pivotal/jasmine-ruby) to run suites in a ruby environment.
11
+
12
+ ### HTML Suite Running
13
+ [Get the latest release from the downloads page](http://github.com/pivotal/jasmine/downloads)
14
+
15
+ Open `example/example_runner.html` in your favorite browser.
16
+
17
+ ### Automatic Suite Running (w/ Selenium)
18
+
19
+ sudo gem sources -a http://gems.github.com
20
+ sudo gem install geminstaller
21
+ git clone git://github.com/pivotal/jasmine.git
22
+ cd jasmine
23
+ sudo geminstaller
24
+ cd examples/ruby
25
+ rake test:ci
26
+
27
+ Releases
28
+ ----------
29
+ 0.10.0 [[download]](http://cloud.github.com/downloads/pivotal/jasmine/jasmine-0.10.0.zip)
30
+
31
+ 0.9.0 [[download]](http://github.com/pivotal/jasmine/zipball/0.9.0)
32
+
33
+ 0.8.0 [[download]](http://github.com/pivotal/jasmine/zipball/0.8.0)
34
+
35
+ ### Which Release Should I Use?
36
+
37
+ Please use the latest version unless you have a good reason not to. Some of this documentation may not be applicable to older versions.
38
+
39
+ Pull Requests
40
+ ----------
41
+ We welcome your contributions! Jasmine is currently maintained by Davis Frank ([infews](http://github.com/infews)), Rajan Agaskar ([ragaskar](http://github.com/ragaskar)), and Christian Williams ([Xian](http://github.com/Xian)). You can help us by removing all other recipients from your pull request.
42
+
43
+
44
+ Why Another JavaScript TDD/BDD Framework?
45
+ -----------
46
+
47
+ There are some great JavaScript testing frameworks out there already, so why did we write another?
48
+
49
+ None of the existing frameworks quite worked the way we wanted. Many only work from within a browser. Most don't support testing asynchronous code like event callbacks. Some have syntax that's hard for JS developers or IDEs to understand.
50
+
51
+ So we decided to start from scratch.
52
+
53
+ Enter Jasmine
54
+ ------------
55
+
56
+ Jasmine is our dream JavaScript testing framework. It's heavily influenced by, and borrows the best parts of, ScrewUnit, JSSpec, [JSpec](http://github.com/visionmedia/jspec/tree/master), and of course RSpec.
57
+
58
+ Jasmine was designed with a few principles in mind. We believe that a good JavaScript testing framework:
59
+
60
+ * should not be tied to any browser, framework, platform, or host language.
61
+ * should have idiomatic and unsurprising syntax.
62
+ * should work anywhere JavaScript can run, including browsers, servers, phones, etc.
63
+ * shouldn't intrude in your application's territory (e.g. by cluttering the global namespace).
64
+ * should play well with IDEs (e.g. test code should pass static analysis).
65
+
66
+ Some of our goals while writing Jasmine:
67
+
68
+ * it should encourage good testing practices.
69
+ * it should integrate easily with continuous build systems.
70
+ * it should be simple to get started with.
71
+
72
+ The result is Jasmine, and we love test-driving our code with it. Enjoy.
73
+
74
+ How To
75
+ ------
76
+
77
+ There is a simple example of how to use Jasmine in the /example directory. But here's more information.
78
+
79
+ ### Specs
80
+
81
+ Each spec is, naturally, a JavaScript function. You tell Jasmine about this spec with a call to `it()` with a string and the function. The string is a description that will be helpful to you when reading a report.
82
+
83
+ it('should be a test', function () {
84
+ var foo = 0;
85
+ foo++;
86
+ });
87
+
88
+ ### Expectations
89
+
90
+ Within your spec you will want to express expectations about the behavior of your application code. These are made with the `expect()` function and expectation matchers, like this:
91
+
92
+ it('should be a test', function () {
93
+ var foo = 0; // set up the world
94
+ foo++; // call your application code
95
+
96
+ expect(foo).toEqual(1); // passes because foo == 1
97
+ });
98
+
99
+ Results of the expectations are logged for later for reporting.
100
+
101
+ #### Expectation Matchers
102
+
103
+ Jasmine has several built-in matchers. Here are a few:
104
+
105
+ >`expect(x).toEqual(y);` compares objects or primitives `x` and `y` and passes if they are equivalent
106
+ >
107
+ >`expect(x).toMatch(pattern);` compares `x` to string or regular expression `pattern` and passes if they match
108
+ >
109
+ >`expect(x).toBeDefined();` passes if `x` is not `undefined`
110
+ >
111
+ >`expect(x).toBeNull();` passes if `x` is not `null`
112
+ >
113
+ >`expect(x).toBeTruthy();` passes if `x` evaluates to true
114
+ >
115
+ >`expect(x).toBeFalsy();` passes if `x` evaluates to false
116
+ >
117
+ >`expect(x).toContain(y);` passes if array or string `x` contains `y`
118
+
119
+ Every matcher's criteria can be inverted by prepending `.not`:
120
+
121
+ >`expect(x).not.toEqual(y);` compares objects or primitives `x` and `y` and passes if they are *not* equivalent
122
+
123
+ #### Writing New Matchers
124
+
125
+ We've provided a small set of matchers that cover many common situations. However, we recommend that you write custom matchers when you want to assert a more specific sort of expectation. Custom matchers help to document the intent of your specs, and can help to remove code duplication in your specs.
126
+
127
+ It's extremely easy to create new matchers for your app. A matcher function receives the actual value as `this.actual`, and zero or more arguments may be passed in the function call. The function should return `true` if the actual value passes the matcher's requirements, and `false` if it does not.
128
+
129
+ Here's the definition of `toBeLessThan()`:
130
+
131
+ toBeLessThan: function(expected) {
132
+ return this.actual < expected;
133
+ };
134
+
135
+ To add the matcher to your suite, call `this.addMatchers()` from within a `before` or `it` block. Call it with an object mapping matcher name to function:
136
+
137
+ beforeEach(function() {
138
+ this.addMatchers({
139
+ toBeVisible: function() { return this.actual.isVisible(); }
140
+ });
141
+ });
142
+
143
+ ### Suites
144
+
145
+ Specs are grouped in Suites. Suites are defined using the global `describe()` function:
146
+
147
+ describe('One suite', function () {
148
+ it('has a test', function () {
149
+ ...
150
+ });
151
+
152
+ it('has another test', function () {
153
+ ...
154
+ });
155
+ });
156
+
157
+ The Suite name is so that reporting is more descriptive.
158
+
159
+ Suites are executed in the order in which `describe()` calls are made, usually in the order in which their script files are included. Additionally, specs within a suite share a functional scope. So you may declare variables inside a describe block and they are accessible from within your specs. For example:
160
+
161
+ describe('A suite with some variables', function () {
162
+ var bar = 0
163
+
164
+ it('has a test', function () {
165
+ bar++;
166
+ expect(bar).toEqual(1);
167
+ });
168
+
169
+ it('has another test', function () {
170
+ bar++;
171
+ expect(bar).toEqual(2);
172
+ });
173
+ });
174
+
175
+ #### beforeEach
176
+
177
+ A suite can have a beforeEach declaration. It takes a function that is run before each spec. For example:
178
+
179
+ describe('some suite', function () {
180
+
181
+ var suiteWideFoo;
182
+
183
+ beforeEach(function () {
184
+ suiteWideFoo = 1;
185
+ });
186
+
187
+ it('should equal bar', function () {
188
+ expect(suiteWideFoo).toEqual(1);
189
+ });
190
+ });
191
+
192
+ A runner can also have beforeEach declarations. Runner beforeEach functions are executed before every spec in all suites, and execute BEFORE suite beforeEach functions. For example:
193
+
194
+ var runnerWideFoo = [];
195
+
196
+ beforeEach(function () {
197
+ runnerWideFoo.push('runner');
198
+ });
199
+
200
+ describe('some suite', function () {
201
+
202
+ beforeEach(function () {
203
+ runnerWideFoo.push('suite');
204
+ });
205
+
206
+ it('should equal bar', function () {
207
+ expect(runnerWideFoo).toEqual(['runner', 'suite']);
208
+ });
209
+ });
210
+
211
+ #### afterEach
212
+
213
+ Similarly, there is an afterEach declaration. It takes a function that is run after each spec. For example:
214
+
215
+ describe('some suite', function () {
216
+
217
+ var suiteWideFoo;
218
+ afterEach(function () {
219
+ suiteWideFoo = 0;
220
+ });
221
+
222
+ it('should equal 1', function () {
223
+ expect(suiteWideFoo).toEqual(1);
224
+ });
225
+
226
+ it('should equal 0 after', function () {
227
+ expect(suiteWideFoo).toEqual(0);
228
+ };
229
+ });
230
+
231
+ A runner can also have an afterEach declarations. Runner afterEach functions are executed after every spec in all suites, and execute AFTER suite afterEach functions. For example:
232
+
233
+ var runnerWideFoo = [];
234
+
235
+ afterEach(function () {
236
+ runnerWideFoo.push('runner');
237
+ });
238
+
239
+ describe('some suite', function () {
240
+
241
+ afterEach(function () {
242
+ runnerWideFoo.push('suite');
243
+ });
244
+
245
+ it('should be empty', function () {
246
+ expect(runnerWideFoo).toEqual([]);
247
+ });
248
+
249
+ it('should be populated after', function () {
250
+ expect(runnerWideFoo).toEqual(['suite', 'runner']);
251
+ };
252
+ });
253
+
254
+ ### Single-spec After functions
255
+
256
+ A spec may ask Jasmine to execute some code after the spec has finished running; the code will run whether the spec finishes successfully or not. Multiple after functions may be given.
257
+
258
+ describe('some suite', function () {
259
+ it(function () {
260
+ var originalTitle = window.title;
261
+ this.after(function() { window.title = originalTitle; });
262
+ MyWindow.setTitle("new value");
263
+ expect(window.title).toEqual("new value");
264
+ });
265
+
266
+
267
+ ### Nested Describes
268
+ Jasmine supports nested describes. An example:
269
+
270
+ describe('some suite', function () {
271
+
272
+ var suiteWideFoo;
273
+
274
+ beforeEach(function () {
275
+ suiteWideFoo = 0;
276
+ });
277
+
278
+ describe('some nested suite', function() {
279
+ var nestedSuiteBar;
280
+ beforeEach(function() {
281
+ nestedSuiteBar=1;
282
+ });
283
+
284
+ it('nested expectation', function () {
285
+ expect(suiteWideFoo).toEqual(0);
286
+ expect(nestedSuiteBar).toEqual(1);
287
+ });
288
+
289
+ });
290
+
291
+ it('top-level describe', function () {
292
+ expect(suiteWideFoo).toEqual(0);
293
+ expect(nestedSuiteBar).toEqual(undefined);
294
+ });
295
+ });
296
+
297
+ ### Spies
298
+
299
+ Jasmine integrates 'spies' that permit many spying, mocking, and faking behaviors.
300
+
301
+ Here are a few examples:
302
+
303
+ var Klass = function () {
304
+ };
305
+
306
+ var Klass.prototype.method = function (arg) {
307
+ return arg;
308
+ };
309
+
310
+ var Klass.prototype.methodWithCallback = function (callback) {
311
+ return callback('foo');
312
+ };
313
+
314
+ ...
315
+
316
+ it('should spy on Klass#method') {
317
+ spyOn(Klass, 'method');
318
+ Klass.method('foo argument');
319
+
320
+ expect(Klass.method).wasCalledWith('foo argument');
321
+ });
322
+
323
+ it('should spy on Klass#methodWithCallback') {
324
+ var callback = Jasmine.createSpy();
325
+ Klass.method(callback);
326
+
327
+ expect(callback).wasCalledWith('foo');
328
+ });
329
+
330
+
331
+ Spies can be very useful for testing AJAX or other asynchronous behaviors that take callbacks by faking the method firing an async call.
332
+
333
+ var Klass = function () {
334
+ };
335
+
336
+ var Klass.prototype.asyncMethod = function (callback) {
337
+ someAsyncCall(callback);
338
+ };
339
+
340
+ ...
341
+
342
+ it('should test async call') {
343
+ spyOn(Klass, 'asyncMethod');
344
+ var callback = Jasmine.createSpy();
345
+
346
+ Klass.asyncMethod(callback);
347
+ expect(callback).wasNotCalled();
348
+
349
+ var someResponseData = 'foo';
350
+ Klass.asyncMethod.mostRecentCall.args[0](someResponseData);
351
+ expect(callback).wasCalledWith(someResponseData);
352
+
353
+ });
354
+
355
+ There are spy-specfic matchers that are very handy.
356
+
357
+ `expect(x).wasCalled()` passes if `x` is a spy and was called
358
+
359
+ `expect(x).wasCalledWith(arguments)` passes if `x` is a spy and was called with the specified arguments
360
+
361
+ `expect(x).wasNotCalled()` passes if `x` is a spy and was not called
362
+
363
+ `expect(x).wasNotCalledWith(arguments)` passes if `x` is a spy and was not called with the specified arguments
364
+
365
+ Spies can be trained to respond in a variety of ways when invoked:
366
+
367
+ `spyOn(x, 'method').andCallThrough()`: spies on AND calls the original function spied on
368
+
369
+ `spyOn(x, 'method').andReturn(arguments)`: returns passed arguments when spy is called
370
+
371
+ `spyOn(x, 'method').andThrow(exception)`: throws passed exception when spy is called
372
+
373
+ `spyOn(x, 'method').andCallFake(function)`: calls passed function when spy is called
374
+
375
+ Spies have some useful properties:
376
+
377
+ `callCount`: returns number of times spy was called
378
+
379
+ `mostRecentCall.args`: returns argument array from last call to spy.
380
+
381
+ `argsForCall[i]` returns arguments array for call `i` to spy.
382
+
383
+ Spies are automatically removed after each spec. They may be set in the beforeEach function.
384
+
385
+ ### Disabling Tests & Suites
386
+
387
+ Specs may be disabled by calling `xit()` instead of `it()`. Suites may be disabled by calling `xdescribe()` instead of `describe()`. A simple find/replace in your editor of choice will allow you to run a subset of your specs.
388
+
389
+ ### Asynchronous Specs
390
+
391
+ You may be thinking, "That's all very nice, but what's this about asynchronous tests?"
392
+
393
+ Well, say you need to make a call that is asynchronous - an AJAX API, event callback, or some other JavaScript library. That is, the call returns immediately, yet you want to make expectations 'at some point in the future' after some magic happens in the background.
394
+
395
+ Jasmine allows you to do this with `runs()` and `waits()` blocks.
396
+
397
+ `runs()` blocks by themselves simply run as if they were called directly. The following snippets of code should provide similar results:
398
+
399
+ it('should be a test', function () {
400
+ var foo = 0
401
+ foo++;
402
+
403
+ expect(foo).toEqual(1);
404
+ });
405
+
406
+ and
407
+
408
+ it('should be a test', function () {
409
+ runs( function () {
410
+ var foo = 0
411
+ foo++;
412
+
413
+ expect(foo).toEqual(1);
414
+ });
415
+ });
416
+
417
+ multiple `runs()` blocks in a spec will run serially. For example,
418
+
419
+ it('should be a test', function () {
420
+ runs( function () {
421
+ var foo = 0
422
+ foo++;
423
+
424
+ expect(foo).toEqual(1);
425
+ });
426
+ runs( function () {
427
+ var bar = 0
428
+ bar++;
429
+
430
+ expect(bar).toEqual(1);
431
+ });
432
+ });
433
+
434
+ `runs()` blocks share functional scope -- `this` properties will be common to all blocks, but declared `var`'s will not!
435
+
436
+ it('should be a test', function () {
437
+ runs( function () {
438
+ this.foo = 0
439
+ this.foo++;
440
+ var bar = 0;
441
+ bar++;
442
+
443
+ expect(this.foo).toEqual(1);
444
+ expect(bar).toEqual(1);
445
+ });
446
+ runs( function () {
447
+ this.foo++;
448
+ var bar = 0
449
+ bar++;
450
+
451
+ expect(foo).toEqual(2);
452
+ expect(bar).toEqual(1);
453
+ });
454
+ });
455
+
456
+ `runs()` blocks exist so you can test asynchronous processes. The function `waits()` works with `runs()` to provide a naive
457
+ timeout before the next block is run. You supply a time to wait before the next `runs()` function is executed. For example:
458
+
459
+ it('should be a test', function () {
460
+ runs(function () {
461
+ this.foo = 0;
462
+ var that = this;
463
+ setTimeout(function () {
464
+ that.foo++;
465
+ }, 250);
466
+ });
467
+
468
+ runs(function () {
469
+ this.expects(this.foo).toEqual(0);
470
+ });
471
+
472
+ waits(500);
473
+
474
+ runs(function () {
475
+ this.expects(this.foo).toEqual(1);
476
+ });
477
+ });
478
+
479
+ What's happening here?
480
+
481
+ * The first call to `runs()` sets call for 1/4 of a second in the future that increments `this.foo`.
482
+ * The second `runs()` is executed immediately and then verifies that `this.foo` was indeed initialized to zero in the previous `runs()`.
483
+ * Then we wait for half a second.
484
+ * Then the last call to `runs()` expects that `this.foo` was incremented by the `setTimeout`.
485
+
486
+ ## Support
487
+ We now have a Google Group for support & discussion.
488
+
489
+ * Homepage: [http://groups.google.com/group/jasmine-js](http://groups.google.com/group/jasmine-js)
490
+ * Group email: [jasmine-js@googlegroups.com](jasmine-js@googlegroups.com)
491
+ * Current build status of Jasmine is visible at [ci.pivotallabs.com](http://ci.pivotallabs.com)
492
+
493
+ ## Maintainers
494
+
495
+ * [Davis W. Frank](mailto:dwfrank@pivotallabs.com), Pivotal Labs
496
+ * [Rajan Agaskar](mailto:rajan@pivotallabs.com), Pivotal Labs
497
+ * [Christian Williams](mailto:xian@pivotallabs.com), Pivotal Labs
498
+
499
+ ## Acknowledgments
500
+ * A big shout out to the various JavaScript test framework authors, especially TJ for [JSpec](http://github.com/visionmedia/jspec/tree/master) - we played with it a bit before deciding that we really needed to roll our own.
501
+ * Thanks to Pivot [Jessica Miller](http://www.jessicamillerworks.com/) for our fancy pass/fail/pending icons
502
+ * Huge contributions have been made by [Erik Hanson](mailto:erik@pivotallabs.com), [Adam Abrons](mailto:adam@pivotallabs.com) and [Carl Jackson](mailto:carl@pivotallabs.com), and many other Pivots.
data/jasmine/Rakefile ADDED
@@ -0,0 +1,158 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), "spec/jasmine_helper.rb"))
2
+
3
+ def jasmine_sources
4
+ sources = ["src/base.js", "src/util.js", "src/Env.js", "src/Reporter.js", "src/Block.js"]
5
+ sources += Dir.glob('src/*.js').reject{|f| f == 'src/base.js' || sources.include?(f)}.sort
6
+ sources
7
+ end
8
+
9
+ def jasmine_filename(version)
10
+ "jasmine-#{version['major']}.#{version['minor']}.#{version['build']}.js"
11
+ end
12
+
13
+ def version_hash
14
+ JSON.parse(File.new("src/version.json").read);
15
+ end
16
+
17
+ def start_jasmine_server(jasmine_includes = nil)
18
+ require File.expand_path(File.join(JasmineHelper.jasmine_root, "contrib/ruby/jasmine_spec_builder"))
19
+
20
+ puts "your tests are here:"
21
+ puts " http://localhost:8888/run.html"
22
+
23
+ Jasmine::SimpleServer.start(
24
+ 8888,
25
+ lambda { JasmineHelper.specs },
26
+ JasmineHelper.dir_mappings,
27
+ :jasmine_files => jasmine_includes)
28
+ end
29
+
30
+ task :default => 'jasmine:dist'
31
+
32
+ namespace :jasmine do
33
+
34
+ desc 'Prepares for distribution'
35
+ task :dist => ['jasmine:build', 'jasmine:doc']
36
+
37
+ desc 'Check jasmine sources for coding problems'
38
+ task :lint do
39
+ passed = true
40
+ jasmine_sources.each do |src|
41
+ lines = File.read(src).split(/\n/)
42
+ lines.each_index do |i|
43
+ line = lines[i]
44
+ undefineds = line.scan(/.?undefined/)
45
+ if undefineds.include?(" undefined") || undefineds.include?("\tundefined")
46
+ puts "Dangerous undefined at #{src}:#{i}:\n > #{line}"
47
+ passed = false
48
+ end
49
+ end
50
+ end
51
+
52
+ unless passed
53
+ puts "Lint failed!"
54
+ exit 1
55
+ end
56
+ end
57
+
58
+ desc 'Builds lib/jasmine from source'
59
+ task :build => [:lint, 'gems:geminstaller'] do
60
+ puts 'Building Jasmine from source'
61
+ require 'json'
62
+
63
+ sources = jasmine_sources
64
+ version = version_hash
65
+
66
+ old_jasmine_files = Dir.glob('lib/jasmine*.js')
67
+ old_jasmine_files.each do |file|
68
+ File.delete(file)
69
+ end
70
+
71
+ jasmine = File.new("lib/#{jasmine_filename version}", 'w')
72
+
73
+ sources.each do |source_filename|
74
+ jasmine.puts(File.read(source_filename))
75
+ end
76
+
77
+ jasmine.puts %{
78
+ jasmine.version_= {
79
+ "major": #{version['major']},
80
+ "minor": #{version['minor']},
81
+ "build": #{version['build']},
82
+ "revision": #{Time.now.to_i}
83
+ };
84
+ }
85
+
86
+ jasmine.close
87
+ end
88
+
89
+ desc "Build jasmine documentation"
90
+ task :doc do
91
+ puts 'Creating Jasmine Documentation'
92
+ require 'rubygems'
93
+ #sudo gem install ragaskar-jsdoc_helper
94
+ require 'jsdoc_helper'
95
+
96
+
97
+ JsdocHelper::Rake::Task.new(:lambda_jsdoc) do |t|
98
+ t[:files] = jasmine_sources << 'lib/TrivialReporter.js'
99
+ t[:options] = "-a"
100
+ end
101
+ Rake::Task[:lambda_jsdoc].invoke
102
+ end
103
+
104
+
105
+ desc "Run jasmine tests of source via server"
106
+ task :server do
107
+ files = jasmine_sources + ['lib/TrivialReporter.js', 'lib/consolex.js']
108
+ jasmine_includes = lambda {
109
+ raw_jasmine_includes = files.collect { |f| File.expand_path(File.join(JasmineHelper.jasmine_root, f)) }
110
+ Jasmine.cachebust(raw_jasmine_includes).collect {|f| f.sub(JasmineHelper.jasmine_src_dir, "/src").sub(JasmineHelper.jasmine_lib_dir, "/lib") }
111
+ }
112
+ start_jasmine_server(jasmine_includes)
113
+ end
114
+
115
+ desc "Build jasmine and run tests via server"
116
+ task :server_build => 'jasmine:build' do
117
+
118
+ start_jasmine_server
119
+ end
120
+
121
+ namespace :test do
122
+ desc "Run continuous integration tests using a local Selenium runner"
123
+ task :ci => :'ci:local'
124
+ namespace :ci do
125
+
126
+ task :local => 'jasmine:build' do
127
+ require "spec"
128
+ require 'spec/rake/spectask'
129
+ Spec::Rake::SpecTask.new(:lambda_ci) do |t|
130
+ t.spec_opts = ["--color", "--format", "specdoc"]
131
+ t.spec_files = ["spec/jasmine_spec.rb"]
132
+ end
133
+ Rake::Task[:lambda_ci].invoke
134
+ end
135
+
136
+ desc "Run continuous integration tests using Sauce Labs 'Selenium in the Cloud'"
137
+ task :saucelabs => ['jasmine:copy_saucelabs_config', 'jasmine:build'] do
138
+ ENV['SAUCELABS'] = 'true'
139
+ Rake::Task['jasmine:test:ci:local'].invoke
140
+ end
141
+ end
142
+ end
143
+
144
+ desc 'Copy saucelabs.yml to work directory'
145
+ task 'copy_saucelabs_config' do
146
+ FileUtils.cp '../saucelabs.yml', 'spec'
147
+ end
148
+ end
149
+
150
+ desc "Run specs via server"
151
+ task :jasmine => ['jasmine:server']
152
+
153
+ namespace :gems do
154
+ desc "Run geminstaller."
155
+ task :geminstaller do
156
+ `geminstaller --sudo`
157
+ end
158
+ end
@@ -0,0 +1,21 @@
1
+ # Project-specific configuration for CruiseControl.rb
2
+ Project.configure do |project|
3
+
4
+ # Send email notifications about broken and fixed builds to email1@your.site, email2@your.site (default: send to nobody)
5
+ # project.email_notifier.emails = ['email1@your.site', 'email2@your.site']
6
+
7
+ # Set email 'from' field to john@doe.com:
8
+ # project.email_notifier.from = 'john@doe.com'
9
+
10
+ # Build the project by invoking rake task 'custom'
11
+ project.rake_task = 'jasmine:test:ci:saucelabs'
12
+
13
+ # Build the project by invoking shell script "build_my_app.sh". Keep in mind that when the script is invoked,
14
+ # current working directory is <em>[cruise&nbsp;data]</em>/projects/your_project/work, so if you do not keep build_my_app.sh
15
+ # in version control, it should be '../build_my_app.sh' instead
16
+ #project.build_command = 'cp ../saucelabs.yml .'
17
+
18
+ # Ping Subversion for new revisions every 5 minutes (default: 30 seconds)
19
+ # project.scheduler.polling_interval = 5.minutes
20
+
21
+ end