Slide 1

Slide 1 text

Sustainable Software

Slide 2

Slide 2 text

Who uses JavaScript?

Slide 3

Slide 3 text

Who’s familiar with Test-Driven Development?

Slide 4

Slide 4 text

Who has code that’s difficult to change?

Slide 5

Slide 5 text

pain points

Slide 6

Slide 6 text

adding new code breaks existing functionality intent & value of the code is unclear HTML & JavaScript become codependent it takes longer to add a new feature than it used to pain points

Slide 7

Slide 7 text

adding new code breaks existing functionality intent & value of the code is unclear HTML & JavaScript become codependent it takes longer to add a new feature than it used to pain points

Slide 8

Slide 8 text

adding new code breaks existing functionality intent & value of the code is unclear HTML & JavaScript become codependent it takes longer to add a new feature than it used to pain points

Slide 9

Slide 9 text

adding new code breaks existing functionality intent & value of the code is unclear HTML & JavaScript become codependent it takes longer to add a new feature than it used to pain points

Slide 10

Slide 10 text

adding new code breaks existing functionality intent & value of the code is unclear HTML & JavaScript become codependent it takes longer to add a new feature than it used to which leads to

Slide 11

Slide 11 text

adding new code breaks existing functionality intent & value of the code is unclear HTML & JavaScript become codependent it takes longer to add a new feature than it used to manual regression testing, change control processes rely on documentation, original authors to retain knowledge developers and designers closely coordinate each change hiring more people, working longer hours which leads to

Slide 12

Slide 12 text

adding new code breaks existing functionality intent & value of the code is unclear HTML & JavaScript become codependent it takes longer to add a new feature than it used to manual regression testing, change control processes rely on documentation, original authors to retain knowledge developers and designers closely coordinate each change hiring more people, working longer hours which leads to

Slide 13

Slide 13 text

adding new code breaks existing functionality intent & value of the code is unclear HTML & JavaScript become codependent it takes longer to add a new feature than it used to manual regression testing, change control processes rely on documentation, original authors to retain knowledge developers and designers closely coordinate each change hiring more people, working longer hours which leads to

Slide 14

Slide 14 text

adding new code breaks existing functionality intent & value of the code is unclear HTML & JavaScript become codependent it takes longer to add a new feature than it used to manual regression testing, change control processes rely on documentation, original authors to retain knowledge developers and designers closely coordinate each change hiring more people, working longer hours which leads to

Slide 15

Slide 15 text

adding new code breaks existing functionality intent & value of the code is unclear HTML & JavaScript become codependent it takes longer to add a new feature than it used to manual regression testing, change control processes rely on documentation, original authors to retain knowledge developers and designers closely coordinate each change hiring more people, working longer hours but we value

Slide 16

Slide 16 text

adding new code breaks existing functionality intent & value of the code is unclear HTML & JavaScript become codependent it takes longer to add a new feature than it used to manual regression testing, change control processes rely on documentation, original authors to retain knowledge developers and designers closely coordinate each change hiring more people, working longer hours shipping features to users constantly avoiding commitments to non-critical concerns minimizing time to turn ideas into reality getting the most out of each infusion of capital but we value

Slide 17

Slide 17 text

adding new code breaks existing functionality intent & value of the code is unclear HTML & JavaScript become codependent it takes longer to add a new feature than it used to manual regression testing, change control processes rely on documentation, original authors to retain knowledge developers and designers closely coordinate each change hiring more people, working longer hours shipping features to users constantly avoiding commitments to non-critical concerns minimizing time to turn ideas into reality getting the most out of each infusion of capital but we value

Slide 18

Slide 18 text

adding new code breaks existing functionality intent & value of the code is unclear HTML & JavaScript become codependent it takes longer to add a new feature than it used to manual regression testing, change control processes rely on documentation, original authors to retain knowledge developers and designers closely coordinate each change hiring more people, working longer hours shipping features to users constantly avoiding commitments to non-critical concerns minimizing time to turn ideas into reality getting the most out of each infusion of capital but we value

Slide 19

Slide 19 text

adding new code breaks existing functionality intent & value of the code is unclear HTML & JavaScript become codependent it takes longer to add a new feature than it used to manual regression testing, change control processes rely on documentation, original authors to retain knowledge developers and designers closely coordinate each change hiring more people, working longer hours shipping features to users constantly avoiding commitments to non-critical concerns minimizing time to turn ideas into reality getting the most out of each infusion of capital but we value

Slide 20

Slide 20 text

adding new code breaks existing functionality intent & value of the code is unclear HTML & JavaScript become codependent it takes longer to add a new feature than it used to manual regression testing, change control processes rely on documentation, original authors to retain knowledge developers and designers closely coordinate each change hiring more people, working longer hours shipping features to users constantly avoiding commitments to non-critical concerns minimizing time to turn ideas into reality getting the most out of each infusion of capital our values are compromised

Slide 21

Slide 21 text

adding new code breaks existing functionality intent & value of the code is unclear HTML & JavaScript become codependent it takes longer to add a new feature than it used to manual regression testing, change control processes rely on documentation, original authors to retain knowledge developers and designers closely coordinate each change hiring more people, working longer hours shipping features to users constantly avoiding commitments to non-critical concerns minimizing time to turn ideas into reality getting the most out of each infusion of capital takes too long for finished features to get into production documentation slows progress; key people become bottlenecks communication cost slows down implementation wastes money & good-will; exacerbates quality issues our values are compromised

Slide 22

Slide 22 text

adding new code breaks existing functionality intent & value of the code is unclear HTML & JavaScript become codependent it takes longer to add a new feature than it used to manual regression testing, change control processes rely on documentation, original authors to retain knowledge developers and designers closely coordinate each change hiring more people, working longer hours shipping features to users constantly avoiding commitments to non-critical concerns minimizing time to turn ideas into reality getting the most out of each infusion of capital takes too long for finished features to get into production documentation slows progress; key people become bottlenecks communication cost slows down implementation wastes money & good-will; exacerbates quality issues our values are compromised

Slide 23

Slide 23 text

adding new code breaks existing functionality intent & value of the code is unclear HTML & JavaScript become codependent it takes longer to add a new feature than it used to manual regression testing, change control processes rely on documentation, original authors to retain knowledge developers and designers closely coordinate each change hiring more people, working longer hours shipping features to users constantly avoiding commitments to non-critical concerns minimizing time to turn ideas into reality getting the most out of each infusion of capital takes too long for finished features to get into production documentation slows progress; key people become bottlenecks communication cost slows down implementation wastes money & good-will; exacerbates quality issues our values are compromised

Slide 24

Slide 24 text

adding new code breaks existing functionality intent & value of the code is unclear HTML & JavaScript become codependent it takes longer to add a new feature than it used to manual regression testing, change control processes rely on documentation, original authors to retain knowledge developers and designers closely coordinate each change hiring more people, working longer hours shipping features to users constantly avoiding commitments to non-critical concerns minimizing time to turn ideas into reality getting the most out of each infusion of capital takes too long for finished features to get into production documentation slows progress; key people become bottlenecks communication cost slows down implementation wastes money & good-will; exacerbates quality issues our values are compromised

Slide 25

Slide 25 text

vicious cycle more bugs communication drag higher carrying cost slower delivery

Slide 26

Slide 26 text

vicious cycle more bugs communication drag higher carrying cost slower delivery more indirection

Slide 27

Slide 27 text

vicious cycle more bugs communication drag higher carrying cost slower delivery less feedback more indirection

Slide 28

Slide 28 text

vicious cycle more bugs communication drag higher carrying cost slower delivery more overtime less feedback more indirection

Slide 29

Slide 29 text

vicious cycle more bugs communication drag higher carrying cost slower delivery more overtime less feedback greater risk more indirection

Slide 30

Slide 30 text

what if? new code didn’t risk breaking existing functionality? all code was sufficiently documented as it was developed? code was modular enough to survive UI changes, multiple client platforms? adding new features became easier over time?

Slide 31

Slide 31 text

what if? new code didn’t risk breaking existing functionality? all code was sufficiently documented as it was developed? code was modular enough to survive UI changes, multiple client platforms? adding new features became easier over time?

Slide 32

Slide 32 text

what if? new code didn’t risk breaking existing functionality? all code was sufficiently documented as it was developed? code was modular enough to survive UI changes, multiple client platforms? adding new features became easier over time?

Slide 33

Slide 33 text

what if? new code didn’t risk breaking existing functionality? all code was sufficiently documented as it was developed? code was modular enough to survive UI changes, multiple client platforms? adding new features became easier over time?

Slide 34

Slide 34 text

virtuous cycle fewer bugs more autonomy easier to change more rapid delivery

Slide 35

Slide 35 text

virtuous cycle fewer bugs more autonomy easier to change more rapid delivery more confidence

Slide 36

Slide 36 text

virtuous cycle fewer bugs more autonomy easier to change more rapid delivery greater value more confidence

Slide 37

Slide 37 text

virtuous cycle fewer bugs more autonomy easier to change more rapid delivery more balance greater value more confidence

Slide 38

Slide 38 text

virtuous cycle fewer bugs more autonomy easier to change more rapid delivery more balance greater value less risk more confidence

Slide 39

Slide 39 text

1. sketch it I want to go to there!

Slide 40

Slide 40 text

1. sketch it 2. spike it I want to go to there!

Slide 41

Slide 41 text

1. sketch it 2. spike it 3. spec it I want to go to there!

Slide 42

Slide 42 text

draw it

Slide 43

Slide 43 text

make it work

Slide 44

Slide 44 text

throw it away

Slide 45

Slide 45 text

spec it

Slide 46

Slide 46 text

build it to last

Slide 47

Slide 47 text

refactor it

Slide 48

Slide 48 text

let’s see an example

Slide 49

Slide 49 text

in your spike, suppose you used

Slide 50

Slide 50 text

$('.add-task').live('click',function(e) { e.preventDefault(); $(this).append('
New Task!
'); });

Slide 51

Slide 51 text

how might we spec adding tasks?

Slide 52

Slide 52 text

describe('#addTask', function(){ it('appends a div'); });

Slide 53

Slide 53 text

describe('#addTask', function(){ it('appends a div', function(){ expect($container).toContain('div'); }); });

Slide 54

Slide 54 text

No content

Slide 55

Slide 55 text

describe('#addTask', function(){ it('appends a div', function(){ var $container = $('
'); expect($container).toContain('div'); }); });

Slide 56

Slide 56 text

No content

Slide 57

Slide 57 text

describe('#addTask', function(){ it('appends a div', function(){ var $container = $('
'); addTask.call($container); expect($container).toContain('div'); }); });

Slide 58

Slide 58 text

No content

Slide 59

Slide 59 text

window.addTask = function(){ this.append('
'); }; describe('#addTask', function(){ it('appends a div', function(){ var $container = $('
'); addTask.call($container); expect($container).toContain('div'); }); });

Slide 60

Slide 60 text

No content

Slide 61

Slide 61 text

describe('#addTask', function(){ it('appends a div', function(){ var $container = $('
'); addTask.call($container); expect($container).toContain('div'); }); it('includes a default text label', function(){ var $container = $('
'); addTask.call($container); expect($container).toHaveText('New Task!'); }); });

Slide 62

Slide 62 text

No content

Slide 63

Slide 63 text

window.addTask = function(){ this.append('
New Task!
'); }; describe('#addTask', function(){ ... it('includes a default text label', function(){ var $container = $('
'); addTask.call($container); expect($container).toHaveText('New Task!'); }); });

Slide 64

Slide 64 text

No content

Slide 65

Slide 65 text

describe('#addTask', function(){ it('appends a div', function(){ var $container = $('
'); addTask.call($container); expect($container).toContain('div'); }); it('includes a default text label', function(){ var $container = $('
'); addTask.call($container); expect($container).toHaveText('New Task!'); }); });

Slide 66

Slide 66 text

describe('#addTask', function(){ var $container; beforeEach(function(){ $container = $('
'); addTask.call($container); }); it('appends a div', function(){ expect($container).toContain('div'); }); it('includes a default text label', function(){ expect($container).toHaveText('New Task!'); }); });

Slide 67

Slide 67 text

describe('#addTask', function(){ var $container; beforeEach(function(){ $container = $('
'); addTask.call($container); }); it('appends a div', function(){ expect($container).toContain('div'); }); it('includes a default text label', function(){ expect($container).toHaveText('New Task!'); }); }); jasmine-jquery http://is.gd/jasminejquery

Slide 68

Slide 68 text

how might we spec event binding?

Slide 69

Slide 69 text

describe('#clicker', function(){ it('triggers the event handler', function(){ expect(handler).toHaveBeenCalledWith(event); }); });

Slide 70

Slide 70 text

No content

Slide 71

Slide 71 text

describe('#clicker', function(){ it('triggers the event handler', function(){ var handler = jasmine.createSpy('handles clicks'); expect(handler).toHaveBeenCalledWith(event); }); });

Slide 72

Slide 72 text

No content

Slide 73

Slide 73 text

describe('#clicker', function(){ it('triggers the event handler', function(){ var handler = jasmine.createSpy('handles clicks'); var event = $.Event('click'); expect(handler).toHaveBeenCalledWith(event); }); });

Slide 74

Slide 74 text

No content

Slide 75

Slide 75 text

describe('#clicker', function(){ it('triggers the event handler', function(){ var handler = jasmine.createSpy('handles clicks'); var event = $.Event('click'); $.jasmine.inject('
'); clicker('.my-button',handler); $('.my-button').trigger(event); expect(handler).toHaveBeenCalledWith(event); }); });

Slide 76

Slide 76 text

No content

Slide 77

Slide 77 text

var clicker = function(selector, whenClicked){ }; describe('#clicker', function(){ it('triggers the event handler', function(){ var handler = jasmine.createSpy('handles clicks'); var event = $.Event('click'); $.jasmine.inject('
'); clicker('.my-button',handler); $('.my-button').trigger(event); expect(handler).toHaveBeenCalledWith(event); }); });

Slide 78

Slide 78 text

No content

Slide 79

Slide 79 text

var clicker = function(selector, whenClicked){ $(selector).live('click',function(e) { whenClicked(e); }); }; describe('#clicker', function(){ it('triggers the event handler', function(){ var handler = jasmine.createSpy('handles clicks'); var event = $.Event('click'); $.jasmine.inject('
'); clicker('.my-button',handler); $('.my-button').trigger(event); expect(handler).toHaveBeenCalledWith(event); }); });

Slide 80

Slide 80 text

No content

Slide 81

Slide 81 text

var clicker = function(selector, whenClicked){ $(selector).live('click',function(e) { whenClicked(e); }); }; describe('#clicker', function(){ ... it('prevents default browser behavior', function(){ var handler = jasmine.createSpy('handles clicks'); var event = $.Event('click'); spyOn(event,'preventDefault'); $.jasmine.inject('
'); clicker('.my-button',handler); $('.my-button').trigger(event); expect(event.preventDefault).toHaveBeenCalled(); }); });

Slide 82

Slide 82 text

No content

Slide 83

Slide 83 text

var clicker = function(selector, whenClicked){ $(selector).live('click',function(e) { e.preventDefault(); whenClicked(e); }); }; describe('#clicker', function(){ ... it('prevents default browser behavior', function(){ var handler = jasmine.createSpy('handles clicks'); var event = $.Event('click'); spyOn(event,'preventDefault'); $.jasmine.inject('
'); clicker('.my-button',handler); $('.my-button').trigger(event); expect(event.preventDefault).toHaveBeenCalled(); }); });

Slide 84

Slide 84 text

No content

Slide 85

Slide 85 text

describe('#clicker', function(){ it('triggers the event handler', function(){ var handler = jasmine.createSpy('handles clicks'); var event = $.Event('click'); $.jasmine.inject('
'); clicker('.my-button',handler); $('.my-button').trigger(event); expect(handler).toHaveBeenCalledWith(event); }); it('prevents default browser behavior', function(){ var handler = jasmine.createSpy('handles clicks'); var event = $.Event('click'); spyOn(event,'preventDefault'); $.jasmine.inject('
'); clicker('.my-button',handler); $('.my-button').trigger(event); expect(event.preventDefault).toHaveBeenCalled(); }); });

Slide 86

Slide 86 text

describe('#clicker',function(){ var handler, event; beforeEach(function(){ handler = jasmine.createSpy('handles clicks'); event = $.Event('click'); spyOn(event,'preventDefault'); $.jasmine.inject('
'); }); context('when you click the button',function(){ beforeEach(function(){ clicker('.my-button',handler); $('.my-button').trigger(event); }); it('triggers the event handler',function(){ expect(handler).toHaveBeenCalledWith(event); }); it('prevents default browser behavior',function(){ expect(event.preventDefault).toHaveBeenCalled(); }); }); });

Slide 87

Slide 87 text

No content

Slide 88

Slide 88 text

describe('#clicker',function(){ var handler, event; beforeEach(function(){ handler = jasmine.createSpy('handles clicks'); event = $.Event('click'); spyOn(event,'preventDefault'); $.jasmine.inject('
'); }); context('when you click the button',function(){ beforeEach(function(){ clicker('.my-button',handler); $('.my-button').trigger(event); }); it('triggers the event handler',function(){ expect(handler).toHaveBeenCalledWith(event); }); it('prevents default browser behavior',function(){ expect(event.preventDefault).toHaveBeenCalled(); }); it('binds `this` to the jQuery result object',function(){ expect(handler.mostRecentCall.object).toBe('.my-button'); }); }); });

Slide 89

Slide 89 text

No content

Slide 90

Slide 90 text

var clicker = function(selector, whenClicked){ $(selector).live('click',function(e) { e.preventDefault(); whenClicked.call($(this),e); }); }; describe('#clicker', function(){ ... context('when you click the button',function(){ ... it('binds `this` to the jQuery result object',function(){ expect(handler.mostRecentCall.object).toBe('.my-button'); }); }); });

Slide 91

Slide 91 text

No content

Slide 92

Slide 92 text

our new production code

Slide 93

Slide 93 text

window.addTask = function(){ this.append('
New Task!
'); }; var clicker = function(selector, whenClicked){ $(selector).live('click',function(e) { e.preventDefault(); whenClicked.call($(this),e); }); }; clicker('.add-task', addTask);

Slide 94

Slide 94 text

$('.add-task').live('click',function(e) { e.preventDefault(); $(this).append('
New Task!
'); });

Slide 95

Slide 95 text

Taking the next step

Slide 96

Slide 96 text

try jasmine https://try-jasmine.heroku.com

Slide 97

Slide 97 text

http://try-jasmine.heroku.com

Slide 98

Slide 98 text

download jasmine http://is.gd/downloadjasmine

Slide 99

Slide 99 text

No content

Slide 100

Slide 100 text

try jasmine-rails https://github.com/searls/jasmine-rails

Slide 101

Slide 101 text

No content

Slide 102

Slide 102 text

No content

Slide 103

Slide 103 text

learn more about test-driven development http://is.gd/tddbook

Slide 104

Slide 104 text

ask us questions and we’ll try to help

Slide 105

Slide 105 text

thank you! [email protected] Boulder UX, Boulder, CO September 12, 2011 @searls seefl[email protected] @seeflanigan Thanks to Brandon Keepers (@bkeepers) for the Keynote template! find this talk at http://is.gd/jasmineux