shuriken 0.1.2.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. data/.gitignore +1 -0
  2. data/Rakefile +28 -0
  3. data/coffeescripts/shuriken/test/assertions.coffee +111 -0
  4. data/coffeescripts/shuriken/test/reporters.coffee +61 -0
  5. data/coffeescripts/shuriken/test.coffee +117 -0
  6. data/coffeescripts/shuriken.coffee +2 -2
  7. data/javascripts/shuriken/mixins/callbacks.js +45 -0
  8. data/javascripts/shuriken/mixins.js +58 -0
  9. data/javascripts/shuriken/test/assertions.js +117 -0
  10. data/javascripts/shuriken/test/reporters.js +84 -0
  11. data/javascripts/shuriken/test.js +165 -0
  12. data/javascripts/shuriken.js +195 -0
  13. data/lib/shuriken.rb +1 -1
  14. data/shuriken.gemspec +84 -4
  15. data/tests/basic_namespace_tests.coffee +114 -0
  16. data/tests/template.erb +26 -0
  17. data/tests.watchr +6 -0
  18. data/vendor/jasmine-0.10.0/MIT.LICENSE +20 -0
  19. data/vendor/jasmine-0.10.0/README.markdown +437 -0
  20. data/vendor/jasmine-0.10.0/doc/files.html +460 -0
  21. data/vendor/jasmine-0.10.0/doc/index.html +322 -0
  22. data/vendor/jasmine-0.10.0/doc/symbols/_global_.html +918 -0
  23. data/vendor/jasmine-0.10.0/doc/symbols/jasmine.Block.html +417 -0
  24. data/vendor/jasmine-0.10.0/doc/symbols/jasmine.Clock.html +678 -0
  25. data/vendor/jasmine-0.10.0/doc/symbols/jasmine.Env.html +1169 -0
  26. data/vendor/jasmine-0.10.0/doc/symbols/jasmine.JsApiReporter.html +822 -0
  27. data/vendor/jasmine-0.10.0/doc/symbols/jasmine.Matchers.html +1461 -0
  28. data/vendor/jasmine-0.10.0/doc/symbols/jasmine.MultiReporter.html +394 -0
  29. data/vendor/jasmine-0.10.0/doc/symbols/jasmine.NestedResults.html +710 -0
  30. data/vendor/jasmine-0.10.0/doc/symbols/jasmine.Reporter.html +574 -0
  31. data/vendor/jasmine-0.10.0/doc/symbols/jasmine.Runner.html +710 -0
  32. data/vendor/jasmine-0.10.0/doc/symbols/jasmine.Spec.html +1259 -0
  33. data/vendor/jasmine-0.10.0/doc/symbols/jasmine.Spy.html +855 -0
  34. data/vendor/jasmine-0.10.0/doc/symbols/jasmine.Suite.html +705 -0
  35. data/vendor/jasmine-0.10.0/doc/symbols/jasmine.html +1345 -0
  36. data/vendor/jasmine-0.10.0/doc/symbols/jasmine.util.html +535 -0
  37. data/vendor/jasmine-0.10.0/doc/symbols/src/lib_TrivialReporter.js.html +124 -0
  38. data/vendor/jasmine-0.10.0/doc/symbols/src/src_Block.js.html +29 -0
  39. data/vendor/jasmine-0.10.0/doc/symbols/src/src_Env.js.html +240 -0
  40. data/vendor/jasmine-0.10.0/doc/symbols/src/src_JsApiReporter.js.html +111 -0
  41. data/vendor/jasmine-0.10.0/doc/symbols/src/src_Matchers.js.html +328 -0
  42. data/vendor/jasmine-0.10.0/doc/symbols/src/src_MultiReporter.js.html +36 -0
  43. data/vendor/jasmine-0.10.0/doc/symbols/src/src_NestedResults.js.html +88 -0
  44. data/vendor/jasmine-0.10.0/doc/symbols/src/src_PrettyPrinter.js.html +130 -0
  45. data/vendor/jasmine-0.10.0/doc/symbols/src/src_Queue.js.html +102 -0
  46. data/vendor/jasmine-0.10.0/doc/symbols/src/src_Reporter.js.html +35 -0
  47. data/vendor/jasmine-0.10.0/doc/symbols/src/src_Reporters.js.html +51 -0
  48. data/vendor/jasmine-0.10.0/doc/symbols/src/src_Runner.js.html +75 -0
  49. data/vendor/jasmine-0.10.0/doc/symbols/src/src_Spec.js.html +211 -0
  50. data/vendor/jasmine-0.10.0/doc/symbols/src/src_Suite.js.html +77 -0
  51. data/vendor/jasmine-0.10.0/doc/symbols/src/src_WaitsBlock.js.html +21 -0
  52. data/vendor/jasmine-0.10.0/doc/symbols/src/src_WaitsForBlock.js.html +45 -0
  53. data/vendor/jasmine-0.10.0/doc/symbols/src/src_base.js.html +555 -0
  54. data/vendor/jasmine-0.10.0/doc/symbols/src/src_mock-timeout.js.html +185 -0
  55. data/vendor/jasmine-0.10.0/doc/symbols/src/src_util.js.html +75 -0
  56. data/vendor/jasmine-0.10.0/example/example_runner.html +25 -0
  57. data/vendor/jasmine-0.10.0/example/spec/example_suite.js +11 -0
  58. data/vendor/jasmine-0.10.0/lib/TrivialReporter.js +117 -0
  59. data/vendor/jasmine-0.10.0/lib/consolex.js +28 -0
  60. data/vendor/jasmine-0.10.0/lib/jasmine-0.10.0.js +2261 -0
  61. data/vendor/jasmine-0.10.0/lib/jasmine.css +86 -0
  62. data/vendor/jasmine-0.10.0/spec/runner.html +63 -0
  63. data/vendor/jasmine-0.10.0/spec/suites/CustomMatchersSpec.js +112 -0
  64. data/vendor/jasmine-0.10.0/spec/suites/EnvSpec.js +71 -0
  65. data/vendor/jasmine-0.10.0/spec/suites/ExceptionsSpec.js +107 -0
  66. data/vendor/jasmine-0.10.0/spec/suites/JsApiReporterSpec.js +82 -0
  67. data/vendor/jasmine-0.10.0/spec/suites/MatchersSpec.js +589 -0
  68. data/vendor/jasmine-0.10.0/spec/suites/MockClockSpec.js +34 -0
  69. data/vendor/jasmine-0.10.0/spec/suites/MultiReporterSpec.js +30 -0
  70. data/vendor/jasmine-0.10.0/spec/suites/NestedResultsSpec.js +54 -0
  71. data/vendor/jasmine-0.10.0/spec/suites/PrettyPrintSpec.js +93 -0
  72. data/vendor/jasmine-0.10.0/spec/suites/QueueSpec.js +23 -0
  73. data/vendor/jasmine-0.10.0/spec/suites/ReporterSpec.js +60 -0
  74. data/vendor/jasmine-0.10.0/spec/suites/RunnerSpec.js +258 -0
  75. data/vendor/jasmine-0.10.0/spec/suites/SpecRunningSpec.js +1086 -0
  76. data/vendor/jasmine-0.10.0/spec/suites/SpecSpec.js +110 -0
  77. data/vendor/jasmine-0.10.0/spec/suites/SpySpec.js +187 -0
  78. data/vendor/jasmine-0.10.0/spec/suites/SuiteSpec.js +101 -0
  79. data/vendor/jasmine-0.10.0/spec/suites/TrivialReporterSpec.js +140 -0
  80. data/vendor/jasmine-0.10.0/spec/suites/UtilSpec.js +23 -0
  81. data/vendor/jquery.js +154 -0
  82. data/wip-coffeescripts/example_test.coffee +0 -0
  83. data/wip-coffeescripts/test/assertions.coffee +111 -0
  84. data/wip-coffeescripts/test/reporters.coffee +61 -0
  85. data/wip-coffeescripts/test.coffee +96 -15
  86. metadata +83 -4
@@ -0,0 +1,437 @@
1
+ Jasmine
2
+ =======
3
+ **YET ANOTHER JavaScript testing framework**
4
+
5
+ Is this the right version for me?
6
+ ---------------------------------
7
+
8
+ This version contains just the Jasmine test framework, a simple reporter, and an example of a runner written as a plain HTML page. If you'd like to run Jasmine via a server, with automatic file discovery and/or in a Continuous Integration environment, please see [http://github.com/pivotal/jasmine](http://github.com/pivotal/jasmine)
9
+
10
+
11
+ Why Another Frickin' JS TDD/BDD Framework?
12
+ -----------
13
+
14
+ There are some situations when you want to test-drive JavaScript, but you don't want to be bothered with or even have an explicit document. You have no DOM to work with and thus lack HTML elements on which to hang event handlers. You may need to make asynchronous calls (say, to an AJAX API) and cannot mock/stub them.
15
+
16
+ But you still need to write tests.
17
+
18
+ What's an Agile Engineer to do?
19
+
20
+ Enter Jasmine
21
+ ------------
22
+
23
+ Jasmine is yet another JavaScript testing framework. It's *heavily* influenced by JSSpec, ScrewUnit & [JSpec](http://github.com/visionmedia/jspec/tree/master), which are all influenced by RSpec. But each of those was lacking in some way: JSSpec & ScrewUnit require a DOM. JSpec's DOM-less assumption was a great start, but it needed asynchronous support.
24
+
25
+ So we started over. And TDD'd a whole new framework. Enjoy.
26
+
27
+ How To
28
+ ------
29
+
30
+ There is a nice example of how to use Jasmine in the /example directory. But here's more information.
31
+
32
+ Exciting changes are afoot and many syntax changes have been made to make Jasmine more usable. Please read the examples below for updates.
33
+
34
+ ### Specs
35
+
36
+ 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.
37
+
38
+ it('should be a test', function () {
39
+ var foo = 0
40
+ foo++;
41
+ });
42
+
43
+ ### Expectations
44
+
45
+ Within your spec you will want/need to make expectations. These are made with the `expect()` funciton and expectation matchers. like this:
46
+
47
+ it('should be a test', function () {
48
+ var foo = 0
49
+ foo++;
50
+
51
+ expect(foo).toEqual(1);
52
+ });
53
+
54
+ Results of the expectations are logged for later for reporting.
55
+
56
+ #### Expectation Matchers
57
+
58
+ Jasmine has several built-in matchers. Here are a few:
59
+
60
+ `toEqual()` compares objects or primitives and returns true if they are equal
61
+
62
+ `toNotEqual()` compares objects or primitives and returns true if they are not equal
63
+
64
+ `toMatch()` takes a regex or a string and returns true if it matches
65
+
66
+ `toNotMatch()` takes a regex or a string and returns true if it does not match
67
+
68
+ `toBeDefined()` returns true if the object or primitive is not `undefined`
69
+
70
+ `toBeNull()` returns true if the object or primitive is not `null`
71
+
72
+ `toBeTruthy()` returns true if the object or primitive evaluates to true
73
+
74
+ `toBeFalsy()` returns true if the object or primitive evaluates to false
75
+
76
+ `toContain()` returns true if an array or string contains the passed variable.
77
+
78
+ `toNotContain()` returns true if an array or string does not contain the passed variable.
79
+
80
+ #### Writing New Matchers
81
+
82
+ A Matcher has a method name, takes an expected value as it's only parameter, has access to the actual value in this, and then makes a call to this.report with true/false with a failure message. Here's the definition of `toEqual()`:
83
+
84
+ jasmine.Matchers.prototype.toEqual = function (expected) {
85
+ return this.report((this.actual === expected),
86
+ 'Expected ' + expected + ' but got ' + this.actual + '.');
87
+ };
88
+
89
+ Feel free to define your own matcher as needed in your code. If you'd like to add Matchers to Jasmine, please write tests.
90
+
91
+ ### Asynchronous Specs
92
+
93
+ You may be thinking, "That's all well and good, but you mentioned something about asynchronous tests."
94
+
95
+ Well, say you need to make a call that is asynchronous - an AJAX API, 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.
96
+
97
+ Jasmine allows you to do this with `runs()` and `waits()` blocks.
98
+
99
+ `runs()` blocks by themselves simply run as if they were called directly. The following snippets of code should provide similar results:
100
+
101
+ it('should be a test', function () {
102
+ var foo = 0
103
+ foo++;
104
+
105
+ expect(foo).toEqual(1);
106
+ });
107
+
108
+ and
109
+
110
+ it('should be a test', function () {
111
+ runs( function () {
112
+ var foo = 0
113
+ foo++;
114
+
115
+ expect(foo).toEqual(1);
116
+ });
117
+ });
118
+
119
+ multiple `runs()` blocks in a spec will run serially. For example,
120
+
121
+ it('should be a test', function () {
122
+ runs( function () {
123
+ var foo = 0
124
+ foo++;
125
+
126
+ expect(foo).toEqual(1);
127
+ });
128
+ runs( function () {
129
+ var bar = 0
130
+ bar++;
131
+
132
+ expect(bar).toEqual(1);
133
+ });
134
+ });
135
+
136
+ `runs()` blocks share functional scope -- `this` properties will be common to all blocks, but declared `var`'s will not!
137
+
138
+ it('should be a test', function () {
139
+ runs( function () {
140
+ this.foo = 0
141
+ this.foo++;
142
+ var bar = 0;
143
+ bar++;
144
+
145
+ expect(this.foo).toEqual(1);
146
+ expect(bar).toEqual(1);
147
+ });
148
+ runs( function () {
149
+ this.foo++;
150
+ var bar = 0
151
+ bar++;
152
+
153
+ expect(foo).toEqual(2);
154
+ expect(bar).toEqual(1);
155
+ });
156
+ });
157
+
158
+ `runs()` blocks exist so you can test asynchronous processes. The function `waits()` works with `runs()` to provide a naive
159
+ timeout before the next block is run. You supply a time to wait before the next `runs()` function is executed. For example:
160
+
161
+ it('should be a test', function () {
162
+ runs(function () {
163
+ this.foo = 0;
164
+ var that = this;
165
+ setTimeout(function () {
166
+ that.foo++;
167
+ }, 250);
168
+ });
169
+
170
+ runs(function () {
171
+ this.expects(this.foo).toEqual(0);
172
+ });
173
+
174
+ waits(500);
175
+
176
+ runs(function () {
177
+ this.expects(this.foo).toEqual(1);
178
+ });
179
+ });
180
+
181
+ What's happening here?
182
+
183
+ * The first call to `runs()` sets call for 1/4 of a second in the future that increments `this.foo`.
184
+ * The second `runs()` is executed immediately and then verifies that `this.foo` was indeed initialized to zero in the previous `runs()`.
185
+ * Then we wait for half a second.
186
+ * Then the last call to `runs()` expects that `this.foo` was incremented by the `setTimeout`.
187
+
188
+
189
+ ### Suites
190
+
191
+ Specs are grouped in Suites. Suites are defined using the global `describe()` function:
192
+
193
+ describe('One suite', function () {
194
+ it('has a test', function () {
195
+ ...
196
+ });
197
+
198
+ it('has another test', function () {
199
+ ...
200
+ });
201
+ });
202
+
203
+ The Suite name is so that reporting is more descriptive.
204
+
205
+ 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:
206
+
207
+ describe('A suite with some variables', function () {
208
+ var bar = 0
209
+
210
+ it('has a test', function () {
211
+ bar++;
212
+ expect(bar).toEqual(1);
213
+ });
214
+
215
+ it('has another test', function () {
216
+ bar++;
217
+ expect(bar).toEqual(2);
218
+ });
219
+ });
220
+
221
+ #### beforeEach
222
+
223
+ A suite can have a beforeEach declaration. It takes a function that is run before each spec. For example:
224
+
225
+ describe('some suite', function () {
226
+
227
+ var suiteWideFoo;
228
+
229
+ beforeEach(function () {
230
+ suiteWideFoo = 1;
231
+ });
232
+
233
+ it('should equal bar', function () {
234
+ expect(suiteWideFoo).toEqual(1);
235
+ });
236
+ });
237
+
238
+ 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:
239
+
240
+ var runnerWideFoo = [];
241
+
242
+ beforeEach(function () {
243
+ runnerWideFoo.push('runner');
244
+ });
245
+
246
+ describe('some suite', function () {
247
+
248
+ beforeEach(function () {
249
+ runnerWideFoo.push('suite');
250
+ });
251
+
252
+ it('should equal bar', function () {
253
+ expect(runnerWideFoo).toEqual(['runner', 'suite']);
254
+ });
255
+ });
256
+
257
+ #### afterEach
258
+
259
+ Similarly, there is an afterEach declaration. It takes a function that is run after each spec. For example:
260
+
261
+ describe('some suite', function () {
262
+
263
+ var suiteWideFoo;
264
+ afterEach(function () {
265
+ suiteWideFoo = 0;
266
+ });
267
+
268
+ it('should equal 1', function () {
269
+ expect(suiteWideFoo).toEqual(1);
270
+ });
271
+
272
+ it('should equal 0 after', function () {
273
+ expect(suiteWideFoo).toEqual(0);
274
+ };
275
+ });
276
+
277
+ 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:
278
+
279
+ var runnerWideFoo = [];
280
+
281
+ afterEach(function () {
282
+ runnerWideFoo.push('runner');
283
+ });
284
+
285
+ describe('some suite', function () {
286
+
287
+ afterEach(function () {
288
+ runnerWideFoo.push('suite');
289
+ });
290
+
291
+ it('should be empty', function () {
292
+ expect(runnerWideFoo).toEqual([]);
293
+ });
294
+
295
+ it('should be populated after', function () {
296
+ expect(runnerWideFoo).toEqual(['suite', 'runner']);
297
+ };
298
+ });
299
+
300
+ ### Nested Describes
301
+ Jasmine supports nested describes. An example:
302
+
303
+ describe('some suite', function () {
304
+
305
+ var suiteWideFoo;
306
+
307
+ beforeEach(function () {
308
+ suiteWideFoo = 0;
309
+ });
310
+
311
+ describe('some nested suite', function() {
312
+ var nestedSuiteBar;
313
+ beforeEach(function() {
314
+ nestedSuiteBar=1;
315
+ });
316
+
317
+ it('nested expectation', function () {
318
+ expect(suiteWideFoo).toEqual(0);
319
+ expect(nestedSuiteBar).toEqual(1);
320
+ });
321
+
322
+ });
323
+
324
+ it('top-level describe', function () {
325
+ expect(suiteWideFoo).toEqual(0);
326
+ expect(nestedSuiteBar).toEqual(undefined);
327
+ });
328
+ });
329
+
330
+ ### Spies
331
+
332
+ Jasmine integrates 'spies' that permit many spying, mocking, and faking behaviors.
333
+
334
+ Here are a few examples:
335
+
336
+ var Klass = function () {
337
+ };
338
+
339
+ var Klass.prototype.method = function (arg) {
340
+ return arg;
341
+ };
342
+
343
+ var Klass.prototype.methodWithCallback = function (callback) {
344
+ return callback('foo');
345
+ };
346
+
347
+ ...
348
+
349
+ it('should spy on Klass#method') {
350
+ spyOn(Klass, 'method');
351
+ Klass.method('foo argument');
352
+
353
+ expect(Klass.method).wasCalledWith('foo argument');
354
+ });
355
+
356
+ it('should spy on Klass#methodWithCallback') {
357
+ var callback = Jasmine.createSpy();
358
+ Klass.method(callback);
359
+
360
+ expect(callback).wasCalledWith('foo');
361
+ });
362
+
363
+
364
+ Spies can be very useful for testing AJAX or other asynchronous behaviors that take callbacks by faking the method firing an async call.
365
+
366
+ var Klass = function () {
367
+ };
368
+
369
+ var Klass.prototype.asyncMethod = function (callback) {
370
+ someAsyncCall(callback);
371
+ };
372
+
373
+ ...
374
+
375
+ it('should test async call') {
376
+ spyOn(Klass, 'asyncMethod');
377
+ var callback = Jasmine.createSpy();
378
+
379
+ Klass.asyncMethod(callback);
380
+ expect(callback).wasNotCalled();
381
+
382
+ var someResponseData = 'foo';
383
+ Klass.asyncMethod.mostRecentCall.args[0](someResponseData);
384
+ expect(callback).wasCalledWith(someResponseData);
385
+
386
+ });
387
+
388
+ There are spy-specfic matchers that are very handy.
389
+
390
+ `wasCalled()` returns true if the object is a spy and was called
391
+
392
+ `wasCalledWith(arguments)` returns true if the object is a spy and was called with the passed arguments
393
+
394
+ `wasNotCalled()` returns true if the object is a spy and was not called
395
+
396
+ `wasNotCalledWith(arguments)` returns true if the object is a spy and was not called with the passed arguments
397
+
398
+ Spies can be trained to respond in a variety of ways when invoked:
399
+
400
+ `andCallThrough()`: spies on AND calls the original function spied on
401
+
402
+ `andReturn(arguments)`: returns passed arguments when spy is called
403
+
404
+ `andThrow(exception)`: throws passed exception when spy is called
405
+
406
+ `andCallFake(function)`: calls passed function when spy is called
407
+
408
+ Spies have some useful properties:
409
+
410
+ `callCount`: returns number of times spy was called
411
+
412
+ `mostRecentCall.args`: returns argument array from last call to spy.
413
+
414
+ `argsForCall[i]` returns arguments array for call `i` to spy.
415
+
416
+ Spies are automatically removed after each spec. They may be set in the beforeEach function.
417
+
418
+ ### Disabling Tests & Suites
419
+
420
+ 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.
421
+
422
+ ## Support
423
+ We now have a Google Group for support & discussion.
424
+
425
+ * Homepage: [http://groups.google.com/group/jasmine-js](http://groups.google.com/group/jasmine-js)
426
+ * Group email: [jasmine-js@googlegroups.com](jasmine-js@googlegroups.com)
427
+
428
+ ## Maintainers
429
+
430
+ * [Davis W. Frank](mailto:dwfrank@pivotallabs.com), Pivotal Labs
431
+ * [Rajan Agaskar](mailto:rajan@pivotallabs.com), Pivotal Labs
432
+ * [Christian Williams](mailto:xian@pivotallabs.com), Pivotal Labs
433
+
434
+ ## Acknowledgments
435
+ * 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.
436
+ * Thanks to Pivot [Jessica Miller](http://www.jessicamillerworks.com/) for our fancy pass/fail/pending icons
437
+ * 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.