-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
680 lines (527 loc) · 15.3 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us" lang="en-us">
<head>
<title>A Survey of Behavior Driven Development in JavaScript</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="stylesheets/main.css" type="text/css" media="screen" charset="utf-8" />
<script type="text/javascript" src="javascripts/jquery.slideshow/vendor/jquery.js"></script>
<script type="text/javascript" src="javascripts/jquery.slideshow/lib/jquery.slideshow.js"></script>
<script type="text/javascript">
$(function() {
$('.slideshow').slideshow({format: 'presentation'});
});
</script>
</head>
<body>
<div class="slideshow">
<div class="first slide">
<h1>A Survey of Behavior-Driven Development in JavaScript</h1>
<br/><br/>
<br/><br/>
<br/><br/>
<h2>T.J. VanSlyke</h2>
<div class="center">
<img src="images/elc.jpg"/>
</div>
<h2>September 4, 2008</h2>
</div>
<div class="slide">
<h1>describe "Presentation" do<br/>
it "has an overview"
</h1>
<ul>
<li>Motivation</li>
<li>Background</li>
<li>Technical hurdles to a friendly solution.</li>
<li>Existing solutions</li>
<li>The future</li>
<li>Community forum</li>
</ul>
</div>
<div class="slide">
<h1>Motivation</h1>
<ul>
<li>No integration of JavaScript testing into developer workflow</li>
<li>Selenium doesn't cut it for day-to-day unit testing</li>
<li>Client-side code is becoming more complex</li>
</ul>
</div>
<div class="slide">
<h1>Motivation</h1>
<ul>
<li>Yet another reason to wake up with keyboard imprints on your face.</li>
</ul>
<div class="center">
<img src="images/passed_out_on_keyboard.gif"/>
</div>
</div>
<div class="slide">
<h1>jSpec</h1>
<div class="center">
<img src="images/jspec.png"/>
</div>
<h2>Features!</h2>
<ul>
<li>Message expectations with quantifiers like RSpec</li>
<li>RSpec-like 'should(Not)' predicate syntax</li>
<li>Nested describe blocks (a la RSpec)</li>
<li>No originality whatsoever</li>
</ul>
</div>
<div class="slide">
<h1>jSpec: Technical hurdles</h1>
<p>JavaScript can perform similarly to Ruby when it comes to syntax-sugar metaprogramming.</p>
<pre>
# Ruby
class Object
def should(matcher, &block)
do_stuff_with(matcher, block)
end
end
</pre>
<pre>
// JavaScript
Object.prototype.should = function(matcher, fn) {
doStuffWith(matcher, fn);
}
</pre>
</div>
<div class="slide">
<h1>jSpec: Technical hurdles</h1>
<p>But unfortunately, the grass isn't greener on the client-side.</p>
<pre class="left">
# Ruby
class Object
def say_hello
puts "Hello!"
end
end
>> nil.a_method
Hello!
</pre>
<pre class="right">
// JavaScript
Object.prototype.aMethod = function() {
// do stuff
}
>> null.aMethod();
TypeError: null has no properties.
</pre>
</div>
<div class="slide">
<h1>jSpec: Technical hurdles</h1>
<p>"Solution": Use a custom selector for all expectations.</p>
<pre>
jSpec.$ = function(expr)
{
if (expr == null)
{
return new jSpec.NullObject();
}
return expr;
}
</pre>
</div>
<div class="slide">
<h1>jSpec</h1>
<pre>
jSpec.describe('this presentation', function($)
{
var presentation;
$.beforeEach(function() {
presentation = { audience: null, boring: false };
});
$.it("should have an audience", function() {
$.$(presentation.audience).shouldNot().beNull();
});
$.it("should not be boring", function() {
$.$(presentation).shouldNot().be('boring');
});
});
</pre>
</div>
<div class="slide">
<h1>jSpec: Message Expectations</h1>
<h2>Example</h2>
<pre>
jSpec.describe('this presentation', function($)
{
var presentation;
$.beforeEach(function() {
presentation = {
begin : function() { alert(this.applause); },
applause: 'woooo!'
};
});
$.it("should receive applause", function() {
$.$(presentation).shouldReceive('applause');
presentation.begin();
});
});
</pre>
</div>
<div class="slide">
<h1>RTFG!</h1>
<div class="center">
<img src="images/ninja-kitten-defeats-dog-with-google-search-skills-always.jpg"/>
</div>
</div>
<div class="slide">
<h1>Other packages</h1>
<ul>
<li>Firebug (JavaScript assertions, http://getfirebug.com)</li>
<li>JsUnit (http://www.jsunit.net/)</li>
<li>QUnit (http://docs.jquery.com/QUnit)</li>
<li>JSSpec (http://code.google.com/p/jsspec/)</li>
<li>Screw.Unit (http://github.com/nkallen/screw-unit/tree/master)</li>
</ul>
</div>
<div class="slide">
<h1>Firebug</h1>
<ul>
<li>Provides a console API for simple assertions</li>
<li>Does <em>not</em> provide a test harness for automation</li>
<li>One platform only (Firefox)</li>
</ul>
</div>
<div class="slide">
<h1>JsUnit</h1>
<h2>From the JsUnit documentation:</h2>
<pre>
function testWithValidArgs() {
assertEquals("2 times 3 plus 5 is 11", 11,
multiplyAndAddFive(2, 3));
assertEquals("Should work with negative numbers", -15,
multiplyAndAddFive(-4, 5));
}
function testWithInvalidArgs() {
assertNull("A null argument should result in null",
multiplyAndAddFive(2, null));
assertNull("A string argument should result in null",
multiplyAndAddFive(2, "a string"));
}
</pre>
</div>
<div class="slide">
<h1>QUnit</h1>
<h2>From the QUnit documentation:</h2>
<pre>
module("Module A");
test("first test within module", function() {
ok( true, "all pass" );
});
test("second test within module", function() {
ok( true, "all pass" );
});
</pre>
</div>
<div class="slide">
<h1>JSSpec</h1>
<h2>From the JSSpec documentation:</h2>
<pre>
describe('Plus operator', {
'should concatenate two strings': function() {
value_of("Hello " + "World").should_be("Hello World");
},
'should add two numbers': function() {
value_of(1 + 2).should_be(3);
}
})
</pre>
</div>
<div class="slide">
<h1>Screw.Unit</h1>
<h2>From the Screw.Unit README:</h2>
<p>Screw.Unit is a Behavior-Driven Testing Framework for Javascript. It features nested describes. Its goals are to provide:</p>
<ul>
<li>a DSL for elegant, readable, organized specs;</li>
<li>an interactive runner that can execute focused specs and describes;</li>
<li>and brief, extensible source-code.</li>
</ul>
</div>
<div class="slide">
<h1>Screw.Unit</h1>
<div class="center">
<img src="images/turtle.jpg"/>
<h2>RADICAL!</h2>
</div>
</div>
<div class="slide">
<h1>Screw.Unit</h1>
<div align="center">
<img src="images/screw-unit-runner.png"/>
</div>
</div>
<div class="slide">
<h1>Screw.Unit</h1>
<pre>
describe('this presentation', function() {
var presentation;
before(function() {
presentation = { audience: null, boring: false };
});
it("should have an audience", function() {
expect(presentation.audience).to_not(be_null);
});
it("should not be boring", function() {
expect(presentation.boring).to_not(be_true);
});
});
</pre>
</div>
<div class="slide">
<h1>Screw.Unit: Time to get meta up in here.</h1>
<pre>
describe("jquery.slideshow", function() {
describe('nextSlide()', function() {
});
describe('previousSlide()', function() {
});
});
</pre>
</div>
<div class="slide">
<h1>Screw.Unit: Time to get meta up in here.</h1>
<pre>
describe('nextSlide()', function() {
it('increments the slide index', function() {});
it('hides the previous slide', function() {});
it('shows the next slide', function() {});
});
</pre>
</div>
<div class="slide">
<h1>Screw.Unit: Time to get meta up in here.</h1>
<pre>
...
it('increments the slide index', function() {
expect(slideshow.slideIndex()).to(equal, 0);
slideshow.nextSlide();
expect(slideshow.slideIndex()).to(equal, 1);
});
...
</pre>
</div>
<div class="slide">
<h1>Screw.Unit: Time to get meta up in here.</h1>
<pre>
it('hides the current slide', function() {
});
</pre>
</div>
<div class="slide">
<h1>Screw.Unit.shouldReceive('messageExpectations')</h1>
<h2>In an ideal world:</h2>
<pre>
it('hides the current slide', function() {
expect(slides[0]).to(receive, 'hide'); // ideal...
slideshow.nextSlide();
});
</pre>
</div>
<div class="slide">
<h1>Screw.Unit.shouldReceive('messageExpectations')</h1>
<h2>In the real world:</h2>
<pre>
...
it('increments the slide index', function() {
expect(slideshow.slideIndex()).to(equal, 0);
slideshow.nextSlide();
expect(slideshow.slideIndex()).to(equal, 1);
});
...
</pre>
</div>
<div class="slide">
<h1>Let's look under the hood...</h1>
<pre>
be_true: {
match: function(expected, actual) {
return actual;
},
failure_message: function(expected, actual, not) {
return 'expected ' + $.print(actual) + (not ? ' to not be true' : ' to be true');
}
},
...
</pre>
<div class="notes">
In order to create a 'receive' matcher, the architecture would need to be changed
to accommodate for post-test callbacks such that we could reconcile the expectations
at the end of the test execution.
</div>
</div>
<div class="slide">
<h1>Stubs and Mocks?</h1>
<ul>
<li>JSMock</li>
<li>Roll your own</li>
</ul>
</div>
<div class="slide">
<h1>JSMock</h1>
<pre>
function Presentation() {
this.boring = function() { /* ... */ };
this.audience = function() { /* ... */ };
}
</pre>
</div>
<div class="slide">
<h1>JSMock</h1>
<pre>
function test_PresentationIsTotallyStellar() {
var mockControl = new MockControl();
presentationMock = mockControl.createMock(Presentation);
var soManyPeople = [ 'all', 'of', 'you', 'beautiful', 'rails', 'enthusiasts' ];
presentationMock.expects().boring().andReturn(false);
presentationMock.expects().audience().andReturn(soManyPeople);
}
</pre>
</div>
<div class="slide">
<h1>JSMock: Yay/Nay</h1>
<h2>Yay!</h2>
<ul>
<li>Expectation recording/matching!</li>
</ul>
<h2>Nay!</h2>
<ul>
<li>Mildly cumbersome syntax</li>
</ul>
</div>
<div class="slide">
<h1>Mock schnell!</h1>
<h2>Or: One Reason To Love Prototype-Based Languages</h2>
<pre>
// A la RSpec mock()
var mock_schnell = {
field: 'value',
another: 123,
method: function() { return 'some mocked value'; }
};
</pre>
</div>
<div class="slide">
<h1>Roll your own: Yay/Nay</h1>
<h2>Yay!</h2>
<ul>
<li>No external libraries and no setup beyond a plain ol' JavaScript object.</li>
</ul>
<h2>Nay!</h2>
<ul>
<li>No expectation recording/matching</li>
</ul>
</div>
<div class="slide">
<h1>Technical hurdles to be solved</h1>
<ul>
<li>No automated cross-browser support</li>
<li>No integration into Rails development workflow (i.e., rake spec)</li>
<li>No mature message expectation engine</li>
<li>No mature mocking/stubbing library</li>
</ul>
</div>
<div class="slide">
<h1>THE FUTURE</h1>
<div class="center">
<img src="images/flyingcar.jpg"/>
</div>
</div>
<div class="slide">
<h1>THE FUTURE</h1>
<h2>HotRuby</h2>
<h3>(a.k.a. "We don't need no stinkin' JavaScript!")</h3>
<ul>
<li>JavaScript virtual machine for Ruby</li>
<li>Runs opcode compiled by YARV (Yet Another Ruby VM)</li>
<li>Developed by Yu Kobayashi</li>
<li>Most grammars are implemented, but it currently lacks exception handling and the majority of Ruby's built-in functions and classes</li>
</ul>
<div class="notes">
</div>
</div>
<div class="slide">
<h1>HotRuby</h1>
<h2>Maybe someday instead of this:</h2>
<pre>
(function($) {
$.fn.slidesnow = function() {
// ...
};
)(jQuery);
</pre>
<h2>We'll do this:</h2>
<pre>
dom_function :slideshow do |element|
# ...
end
</pre>
</div>
<div class="slide">
<h1>HotRuby</h1>
<pre class="left">
describe "my sweet client-side
Ruby slideshow app" do
before(:each) do
@slideshow = tag(:div).slideshow!
@slides =
[
tag(:div, class => 'slide'),
tag(:div, class => 'slide'),
tag(:div, class => 'slide')
]
@slideshow.stub!(:slides).
and_return(@slides)
end
</pre>
<pre class="right">
describe "next_slide" do
it "hides the current slide" do
@slides[0].should_receive(:hide)
@slideshow.next_slide
end
it "increments the slide index" do
@slideshow.slide_index.should == 0
@slideshow.next_slide
@slideshow.slide_index.should == 1
end
it "shows the current slide" do
@slides[1].should_receive(:show)
@slideshow.next_slide
end
end
end
</pre>
<div class="notes">
Here is what client-side RSpec <em>could</em> look like...
Note that there isn't much here you couldn't do with RJS; however, also note that
this gives the flexibility to fully-spec running client-side code.
</div>
</div>
<div class="slide">
<h1>HotRuby: Problems to solve</h1>
<ul>
<li>We need a full Ruby implementation.</li>
<li>How do we access the DOM? DOM Events?</li>
<li>How can we integrate JavaScript tests into our daily rake tasks?</li>
<li>How can we accommodate for multiple JavaScript implementations?</li>
</ul>
</div>
<div class="slide">
<h1>Your turn!</h1>
<div class="center">
<img src="images/elmo.jpg"/>
</div>
<h2>What are <em>you</em> using to test your JavaScript?</h2>
</div>
<div class="slide">
<h1>FIN.</h1>
<div class="center">
<img src="images/mrrogers.jpg"/>
</div>
<h2>github.com/teejayvanslyke/railsconfeurope2008</h2>
</div>
</div>
</body>
</html>