diff --git a/index.html b/index.html index 6dc7166..80cb836 100644 --- a/index.html +++ b/index.html @@ -95,10 +95,8 @@
require 'spec_helper'
-
-describe MyCoolWebsite do
+
describe MyCoolWebsite do
let(:website) { described_class.new }
describe '#cool_method' do
@@ -108,7 +106,8 @@
let(:double_cool) { 'double cool' }
before do
- website.stubs(:whoa_cool).returns(oh_yeah)
+ website.stubs(:whoa_cool).
+ returns(oh_yeah)
end
it { should == double_cool }
@@ -131,23 +130,32 @@
-
<script type="text/javascript">
-function showMyCoolTitle(title, length) {
+
function showMyCoolTitle(title, length) {
if (length == null) { length = 0; }
if (length <= title.length) {
- document.title = title.substr(0, length);
+ document.title =
+ title.substr(0, length);
+
length++;
- setTimeout(function() { showMyCoolTitle(title, length); }, 75);
+ setTimeout(function() {
+ showMyCoolTitle(title, length);
+ }, 75);
}
}
+
window.onload = function() {
+ showMyCoolTitle(
+ "My cool website! Whoaaaaa!"
+ );
}
-</script>
require 'spec_helper'
-
-describe MyCoolWebsite do
+
describe MyCoolWebsite do
let(:website) { described_class.new }
describe '#cool_method' do
@@ -178,7 +184,8 @@
let(:double_cool) { 'double cool' }
before do
- website.stubs(:whoa_cool).returns(oh_yeah)
+ website.stubs(:whoa_cool).
+ returns(oh_yeah)
end
it { should == double_cool }
@@ -189,22 +196,21 @@
-
describe 'MyCoolWebsiteView', ->
- website = null
-
beforeEach ->
- website = new MyCoolWebsiteView()
+ @website = new MyCoolWebsiteView()
describe '#coolMethod', ->
doubleCool = 'double cool'
ohYeah = [ doubleCool ]
beforeEach ->
- website.whoaCool = -> ohYeah
+ @website.whoaCool = -> ohYeah
it 'should be double cool', ->
- expect(website.coolMethod()).toEqual(doubleCool)
+ expect(@website.coolMethod()).
+ toEqual(doubleCool)
describe 'Cat', ->
describe '#meow', ->
- # description of the meow behavior goes here
+ # description of the
+ # meow behavior goes here
describe 'John', ->
describe 'spec definitions', ->
@@ -356,7 +363,7 @@
# code-under-test
-class this.Cat
+class @Cat
meow: ->
// safety wrapper to prevent global pollution
(function() {
- // ...but we want to pollute the Cat class
this.Cat = (function() {
function Cat() {}
Cat.prototype.meow = function() {};
@@ -394,7 +400,7 @@ Expected undefined to equal 'meow'.
Make it meow!
class this.Cat
+class @Cat
meow: -> "meow"
@@ -426,7 +432,7 @@ Expected undefined to equal 'meow'.
# code-under-test
-class this.Cat
+class @Cat
meow: -> "meow"
describe
describe 'Cat', ->
describe '#meow', ->
describe 'hungry', ->
@@ -458,24 +464,27 @@ Expected undefined to equal 'meow'.
-
describe 'Cat', ->
- describe '#meow', ->
- describe 'hungry', ->
- it 'should be a mournful meow', ->
- cat = new Cat()
- cat.state = -> Cat.HUNGRY
- # ...just like cat.stubs(:state)
+
describe 'hungry', ->
+ it 'should be a mournful meow', ->
+ cat = new Cat()
+ cat.state = -> Cat.HUNGRY
+ # ...just like cat.stubs(:state)
- expect(cat.meow()).toEqual("meeeyaow")
+ 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
+
+ expect(cat.meow()).toEqual("raowwww")
describe 'Cat', ->
describe '#meow', ->
beforeEach ->
@cat = new Cat()
+
describe 'hungry', ->
+ it 'should be a mournful meow', ->
+ @cat.state = -> Cat.HUNGRY
+
+ expect(@cat.meow()).toEqual("meeeyaow")
+
describe 'going to the vet', ->
+ it 'should be an evil meow', ->
+ @cat.state = -> Cat.VET_PSYCHIC
+
+ expect(@cat.meow()).toEqual("raowwww")
describe Cat do
describe '#meow' do
describe 'hungry' do
@@ -615,11 +634,12 @@ Expected undefined to equal 'meow'.
-
describe Cat do
let(:cat) { described_class.new }
- # save describe for things or behaviors...
+ # save describe for
+ # things or behaviors...
describe '#meow' do
subject { cat.meow }
@@ -691,7 +711,7 @@ Expected undefined to equal 'meow'.
class this.Cat
+class @Cat
@HUNGRY = 'hungry'
@VET_PSYCHIC = 'vet psychic'
@@ -728,7 +748,7 @@ Expected undefined to equal 'meow'.
expect(cat.meow()).toEqual("meow")
-expect(cat.prototype).toEqual(Cat.prototype)
+expect(cat.constructor).toEqual(Cat)
expect(cat.isHungry()).not.toBeTruthy()
describe 'Cat', ->
beforeEach ->
@cat = new Cat()
@@ -823,20 +848,20 @@ Expected undefined to equal 'meow'.
Feature: Cat Behaviors
- Scenario: Hungry cats meow a particular way
+ Scenario: Hungry cats meow a certain way
Given I have a cat
And the cat is hungry
When the cat meows
- Then the meow should sound like "meeyaow"
+ Then the meow should be a "meeyaow"
class this.Cat
+class @Cat
@FOOD_THRESHOLD = 20
@HUNGRY = 'hungry'
@@ -855,7 +880,7 @@ Expected undefined to equal 'meow'.
-
describe 'Cat', ->
describe '#meow', ->
context 'hungry', ->
@@ -863,7 +888,8 @@ Expected undefined to equal 'meow'.
cat = new Cat()
cat.foodLevel = 15
- expect(cat.meow()).toEqual("meeeyaow")
+ expect(cat.meow()).
+ toEqual("meeeyaow")
class this.Cat
+
class @Cat
meow: ->
- switch this.state() # <= dependent code executed
+ switch this.state()
+ # ^^^ dependent code executed
when Cat.HUNGRY
"meeyaow"
cat.foodLevel = 15
- # do we care about food level in this test?
- # all we care about is that the cat is hungry
+ # do we care about food level?
describe 'Cat', ->
describe '#meow', ->
- describe 'hungry', ->
+ context '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
+ # ^^^ we just want a hungry cat
- expect(cat.meow()).toEqual("meeeyaow")
+ expect(cat.meow()).
+ toEqual("meeeyaow")
class this.Cat
+class @Cat
state: ->
# cat codes
@@ -949,7 +975,7 @@ Expected undefined to equal 'meow'.
class this.Cat
+class @Cat
vocalProcessor: (speech) =>
if this.isAirborne()
this.modifyForAirborne(speech)
@@ -960,7 +986,7 @@ Expected undefined to equal 'meow'.
-
describe 'Cat#vocalProcessor', ->
speech = "speech"
@@ -974,7 +1000,8 @@ Expected undefined to equal 'meow'.
it 'should be modified for flight', ->
@cat.vocalProcessor(speech)
- expect(@cat.modifyForAirborne).toHaveBeenCalledWith(speech)
+ expect(@cat.modifyForAirborne).
+ toHaveBeenCalledWith(speech)
toHaveBeenCalledWith(args...)
expect(@cat.modifyForAirborne).toHaveBeenCalledWith(speech)
+expect(@cat.modifyForAirborne).
+ toHaveBeenCalledWith(speech)
-
toHaveBeenCalled()
expect(@cat.modifyForAirborne).toHaveBeenCalled()
+expect(@cat.modifyForAirborne).
+ toHaveBeenCalled()
-
spyOn
/toHaveBeenCalled
matchersclass this.Cat
+class @Cat
state: ->
# cat codes
cat = new Cat()
spyOn(cat, 'state')
-expect(cat.state).toHaveBeenCalled()
+expect(cat.state).
+ toHaveBeenCalled()
@@ -1037,14 +1067,16 @@ Expected undefined to equal 'meow'.
spyOn
works great with class-level stubs and mocks, tooclass this.Cat
+
class @Cat
@generateFurColor: (base) ->
# magicks to make a fur color given a base
regrowFur: (damagedHairs) ->
for follicle in damagedHairs
- follicle.regrow(Cat.generateFurColor(this.baseColor))
+ follicle.regrow(
+ Cat.generateFurColor(this.baseColor)
+ )
describe 'Cat#regrowFur', ->
color = 'color'
beforeEach ->
@cat = new Cat()
- @follicle =
- regrow: ->
-
+ @follicle = { regrow: -> null }
@follicles = [ follicle ]
- spyOn(Cat, 'generateFurColor').andReturn(color)
- # ^^^ original is replaced when done
+ spyOn(Cat, 'generateFurColor').
+ # ^^^ original replaced when done
+ andReturn(color)
spyOn(@follicle, 'regrow')
it 'should regrow', ->
@cat.regrowFur(@follicles)
- expect(@follicle.regrow).toHaveBeenCalledWith(color)
+ expect(@follicle.regrow).
+ toHaveBeenCalledWith(color)
# fast and focused!
describe 'Cat#respondsTo', ->
@@ -1169,8 +1201,11 @@ Expected undefined to equal 'meow'.
context 'successes', ->
it 'should respond', ->
- for request in [ 'kitty kitty', 'pookums', 'hisshead' ]
- expect(@cat.respondsTo(request)).toBeTruthy()
+ for request in [ 'kitty kitty',
+ 'pookums',
+ 'hisshead' ]
+ expect(@cat.respondsTo(request)).
+ toBeTruthy()
$.fn
callsthis.containerWaiter = ->
- $('#container').addClass('wait').append('<div class="waiting" />')
+ $('#container').
+ addClass('wait').
+ append('<div class="waiting" />')
$.fn.makeWait = ->
- $(this).addClass('wait').append('<div class="waiting" />')
+ $(this).
+ addClass('wait').
+ append('<div class="waiting" />')
this
jquery-jasmine
describe 'container', ->
beforeEach ->
setFixtures('<div id="container" />')
it 'should make it wait', ->
containerWaiter()
- expect($('#container')).toHaveClass('wait')
- expect($('#container')).toContain('div.waiting')
+
+ expect($('#container')).
+ toHaveClass('wait')
+ expect($('#container')).
+ toContain('div.waiting')
class Cat
+class @Cat
constructor: ->
@mood = "happy"
@@ -1441,10 +1484,6 @@ Expected undefined to equal 'meow'.