diff --git a/_site/assets/application.js b/_site/assets/application.js index 0681966..07e801e 100644 --- a/_site/assets/application.js +++ b/_site/assets/application.js @@ -240,26 +240,38 @@ Attentive.PresentationTimer = (function() { PresentationTimer.prototype.ensureEl = function() { if (!this.el) { - this.el = document.createElement('div'); + this.el = this._createDiv(); this.el.classList.add('timer'); } return this.el; }; + PresentationTimer.prototype._createDiv = function() { + return document.createElement('div'); + }; + + PresentationTimer.prototype.addClass = function(className) { + return this.ensureEl().classList.add(className); + }; + PresentationTimer.prototype.start = function() { this._runner = this.runner(); - return this.ensureEl().classList.add('running'); + return this.addClass('running'); }; PresentationTimer.prototype.runner = function() { var _this = this; return setTimeout(function() { - _this.render(); - _this.time += 1; - if (_this._runner != null) return _this.runner(); + return _this.handleRunner(); }, 1000); }; + PresentationTimer.prototype.handleRunner = function() { + this.render(); + this.time += 1; + if (this._runner != null) return this.runner(); + }; + PresentationTimer.prototype.stop = function() { clearTimeout(this._runner); this.ensureEl().classList.remove('running'); diff --git a/_site/index.html b/_site/index.html index c962821..b29c00a 100644 --- a/_site/index.html +++ b/_site/index.html @@ -133,12 +133,12 @@ -
+
<script type="text/javascript">
 function showMyCoolTitle(title, length) {
   if (length == null) { length = 0; }
 
-  if (length < title.length) {
+  if (length <= title.length) {
     document.title = title.substr(0, length);
     length++;
 
@@ -146,7 +146,9 @@
   }
 }
 
-window.onload = function() { showMyCoolTitle("My cool website! Whoaaaaa!"); }
+window.onload = function() {
+  showMyCoolTitle("My cool website! Whoaaaaa!");
+}
 </script>
 
@@ -232,7 +234,7 @@

Follow along!

-

johnbintz.github.com/tea-time

+

johnbintz.github.com/tea-time

No need to install anything right now

@@ -282,7 +284,7 @@

-
+
describe 'Cat', ->
   describe '#meow', ->
     # description of the meow behavior goes here
@@ -373,7 +375,7 @@
 
 
 
-
+
// safety wrapper to prevent global pollution
 (function() {
   // ...but we want to pollute the Cat class
@@ -463,10 +465,12 @@ Expected undefined to equal 'meow'.
 
describe 'Cat', ->
   describe '#meow', ->
     describe 'hungry', ->
-      # Cat#meow expectation for when the cat is hungry
+      # Cat#meow expectation for when
+      # the cat is hungry
 
     describe 'going to the vet', ->
-      # Cat#meow expectation for when the cat knows it's vet time
+      # Cat#meow expectation for when
+      # the cat knows it's vet time
 
@@ -479,14 +483,16 @@ Expected undefined to equal 'meow'. describe 'hungry', -> it 'should be a mournful meow', -> cat = new Cat() - cat.state = -> Cat.HUNGRY # ...just like cat.stubs(:state) + cat.state = -> Cat.HUNGRY + # ...just like cat.stubs(:state) expect(cat.meow()).toEqual("meeeyaow") describe 'going to the vet', -> it 'should be an evil meow', -> cat = new Cat() - cat.state = -> Cat.VET_PSYCHIC # ...just like the one above + cat.state = -> Cat.VET_PSYCHIC + # ...just like the one above expect(cat.meow()).toEqual("raowwww")
@@ -535,7 +541,7 @@ Expected undefined to equal 'meow'. @instance_variable = "yes" end -it "should be in the same context as the before block" do +it "is in same context as before block" do @instance_variable.should == "yes" end @@ -749,7 +755,8 @@ Expected undefined to equal 'meow'.
cat.meow.should == "meow"
 cat.should be_a_kind_of(Cat)
-cat.should_not be_hungry #=> cat.hungry?.should == false
+cat.should_not be_hungry
+  # => cat.hungry?.should == false
 
@@ -859,7 +866,7 @@ Expected undefined to equal 'meow'.

-
+
Feature: Cat Behaviors
   Scenario: Hungry cats meow a particular way
     Given I have a cat
@@ -893,7 +900,7 @@ Expected undefined to equal 'meow'.
 
 
 
-
+
describe 'Cat', ->
   describe '#meow', ->
     context 'hungry', ->
@@ -927,8 +934,9 @@ Expected undefined to equal 'meow'.
 

Why make your unit tests fragile?

-
cat.foodLevel = 15 # do we care about food level in this test?
-                   # all we care about is that the cat is hungry
+
cat.foodLevel = 15
+  # do we care about food level in this test?
+    # all we care about is that the cat is hungry
 
@@ -941,8 +949,9 @@ Expected undefined to equal 'meow'. describe 'hungry', -> it 'should be a mournful meow', -> cat = new Cat() - cat.state = -> Cat.HUNGRY # <= we don't care how state works, - # we just want a hungry cat + cat.state = -> Cat.HUNGRY + # ^^^ we don't care how state works, + # we just want a hungry cat expect(cat.meow()).toEqual("meeeyaow")
@@ -1002,7 +1011,7 @@ Expected undefined to equal 'meow'. -
+
describe 'Cat#vocalProcessor', ->
   speech = "speech"
 
@@ -1039,10 +1048,10 @@ Expected undefined to equal 'meow'.
 

Two basic ways to make sure a spy is called

-
-

toHaveBeenCalledWith()

+
+

toHaveBeenCalledWith(args...)

-

Called least once with the given parameters

+

Called least once with the given parameters

expect(@cat.modifyForAirborne).toHaveBeenCalledWith(speech)
 
@@ -1051,10 +1060,10 @@ Expected undefined to equal 'meow'. -
-

toHaveBeenCalled()

+
+

toHaveBeenCalled()

-

Just called, no parameter check

+

Just called, no parameter check

expect(@cat.modifyForAirborne).toHaveBeenCalled()
 
@@ -1063,7 +1072,7 @@ Expected undefined to equal 'meow'. -
+

Instance Mocks/Spies in JavaScript

Use spyOn/toHaveBeenCalled matchers

@@ -1084,7 +1093,7 @@ Expected undefined to equal 'meow'.

spyOn works great with class-level stubs and mocks, too

-
+
class this.Cat
   @generateFurColor: (base) ->
     # magicks to make a fur color given a base
@@ -1098,7 +1107,7 @@ Expected undefined to equal 'meow'.
 
 
 
-
+
Cat.generateFurColor = ->
   "whoops i nuked this method for every other test"
 
@@ -1107,7 +1116,7 @@ Expected undefined to equal 'meow'. -
+
describe 'Cat#regrowFur', ->
   color = 'color'
 
@@ -1132,7 +1141,7 @@ Expected undefined to equal 'meow'.
 
 
 
-
+

Class Stubs in JavaScript

Use spyOn to generate stubs so that the original code is replaced after the test

@@ -1213,7 +1222,7 @@ Expected undefined to equal 'meow'.

Sometimes you just need a big blob of unit tests

-
+
# fast and focused!
 
 describe 'Cat#respondsTo', ->
@@ -1230,7 +1239,7 @@ Expected undefined to equal 'meow'.
 
 
 
-
+
# slow and synergistic!
 
 Scenario Outline: Successful responsiveness
@@ -1262,7 +1271,7 @@ Expected undefined to equal 'meow'.
 

Using it in your project

Starts a Rack server for running Jasmine against your code

@@ -1300,7 +1309,7 @@ Expected undefined to equal 'meow'.

Mocking and stubbing $.fn calls

-
+
this.containerWaiter = ->
   $('#container').addClass('wait').append('<div class="waiting" />')
 
@@ -1309,7 +1318,7 @@ Expected undefined to equal 'meow'. -
+
$.fn.makeWait = ->
   $(this).addClass('wait').append('<div class="waiting" />')
   this
@@ -1331,7 +1340,7 @@ Expected undefined to equal 'meow'.
 

jquery-jasmine

-
+
describe 'container', ->
   beforeEach ->
     setFixtures('<div id="container" />')
@@ -1472,44 +1481,7 @@ Expected undefined to equal 'meow'.
 
 
 
-
-
CatLike =
-  catify: (name) -> "meow meow #{name}"
-
-class Cat
-  hiss: -> "hiss"
-
-# like Ruby include, add code to instances
-for method, code of CatLike
-  Cat.prototype[method] = code
-
-cat = new Cat()
-cat.catify("john") # => "meow meow #{name}"
-
-
- - - - -
-
CatLike =
-  catify: (name) -> "meow meow #{name}"
-
-class Cat
-  hiss: -> "hiss"
-
-# like Ruby extend, add code to class
-for method, code of CatLike
-  Cat[method] = code
-
-Cat.catify("john") # => "meow meow john"
-
-
- - - - -
+
describe '_.catify', ->
   it 'should catify', ->
     expect(_.catify("hiss")).toEqual("meow meow hiss")
@@ -1522,7 +1494,7 @@ Expected undefined to equal 'meow'.
 

Eliminate the Underscore.js dependency

-
+
describe 'CatLike', ->
   beforeEach ->
     @helper = {}
@@ -1585,10 +1557,10 @@ Expected undefined to equal 'meow'.
 
 
 

Any questions?