Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Jasmine for Rubyists @ #rockymtnruby with Cory Flanigan & Justin Searls

Justin Searls
September 02, 2011

Jasmine for Rubyists @ #rockymtnruby with Cory Flanigan & Justin Searls

Presented at Rocky Mountain Ruby on September 2, 2011.

Justin Searls

September 02, 2011
Tweet

More Decks by Justin Searls

Other Decks in Programming

Transcript

  1. why? it’s hard it’s just glue code it’s covered by

    selenium too many tools, not enough convention
  2. why? it’s hard it’s just glue code it’s covered by

    selenium too many tools, not enough convention it’s just UI flair
  3. why? it’s hard it’s just glue code it’s covered by

    selenium too many tools, not enough convention it’s just UI flair page refresh-driven development
  4. why? it’s hard no one expects me to do it

    it’s just glue code it’s covered by selenium too many tools, not enough convention it’s just UI flair page refresh-driven development
  5. function loadIt(){ /* This separate function simply saves parsing the

    database for each search. The arrayflg is used to flag that it has been done. */ arrayflg=1; /* First, read in the string from the hidden form element. */ ls=document.ug.ly.value; ctr=0; /* Then parse the long string and load it into the array. */ while (ls.indexOf("*")>-1){ pos=ls.indexOf("*"); db[ctr]=ls.substring(0,pos); /* Similarly, no need to repeatedly convert the strings in the array to lower case. Once is enough. */ dblc[ctr]=db[ctr].toLowerCase(); ls=ls.substring(pos+1,ls.length); ctr++; } } so many comments. What does it do? This code has /* This separate function simply saves parsing the database for each search. The arrayflg is used to flag that it has been done. */ /* First, read in the string from the hidden form element. */ /* Then parse the long string and load it into the array. */ /* Similarly, no need to repeatedly convert the strings in the array to lower case. Once is enough. */ function loadIt(){ arrayflg=1; ls=document.ug.ly.value; ctr=0; while (ls.indexOf("*")>-1){ pos=ls.indexOf("*"); db[ctr]=ls.substring(0,pos); dblc[ctr]=db[ctr].toLowerCase(); ls=ls.substring(pos+1,ls.length); ctr++; } }
  6. “experience experience experience context context context context context context context

    context context context context context caveats caveats caveats caveats “I basically never pair.” http://is.gd/pairing Jay Fields
  7. “experience experience experience context context context context context context context

    context context context context context caveats caveats caveats caveats “I don’t do JavaScript.” Unknown
  8. ...teach them how to fish. So, we could rescue them,

    or... they’re drowning in a sea of untested code! I see.
  9. describe('#addTask', function(){ var $container; beforeEach(function(){ $container = $('<div></div>'); addTask.call($container); });

    it('appends a div', function(){ expect($container).toContain('div'); }); it('includes a default text label', function(){ expect($container).toHaveText('New Task!'); }); });
  10. describe('#addTask', function(){ var $container; beforeEach(function(){ $container = $('<div></div>'); 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
  11. describe('#clicker',function(){ var handler, event; beforeEach(function(){ handler = jasmine.createSpy('handles clicks'); event

    = $.Event('click'); spyOn(event,'preventDefault'); $.jasmine.inject('<div class="my-button"></div>'); }); 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('binds `this` to the jQuery result object',function(){ expect(handler.mostRecentCall.object).toBe('.my-button'); }); it('prevents default browser behavior',function(){ expect(event.preventDefault).toHaveBeenCalled(); }); }); });
  12. describe('#clicker',function(){ var handler, event; beforeEach(function(){ handler = jasmine.createSpy('handles clicks'); event

    = $.Event('click'); spyOn(event,'preventDefault'); $.jasmine.inject('<div class="my-button"></div>'); }); 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('binds `this` to the jQuery result object',function(){ expect(handler.mostRecentCall.object).toBe('.my-button'); }); it('prevents default browser behavior',function(){ expect(event.preventDefault).toHaveBeenCalled(); }); }); });
  13. describe('#clicker',function(){ var handler, event; beforeEach(function(){ handler = jasmine.createSpy('handles clicks'); event

    = $.Event('click'); spyOn(event,'preventDefault'); $.jasmine.inject('<div class="my-button"></div>'); }); 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('binds `this` to the jQuery result object',function(){ expect(handler.mostRecentCall.object).toBe('.my-button'); }); it('prevents default browser behavior',function(){ expect(event.preventDefault).toHaveBeenCalled(); }); }); });
  14. describe '#clicker', -> handler=event=null; beforeEach -> handler = jasmine.createSpy 'handles

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

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

    clicks' event = $.Event 'click' spyOn event, 'preventDefault' $.jasmine.inject '<div class="my-button"></div>' context 'when you click the button', -> beforeEach -> clicker '.my-button', handler $('.my-button').trigger(event) it 'triggers the event handler', -> expect(handler).toHaveBeenCalledWith(event) it 'binds `this` to the jQuery result object', -> expect(handler.mostRecentCall.object).toBe('.my-button') it 'prevents default browser behavior', -> expect(event.preventDefault).toHaveBeenCalled()
  17. Consider coming to our non-profit JavaScript Craftsmanshop next week in

    Denver @ Uncubed on 9/8 & 9/9 register at http://is.gd/jasmine Use coupon code RMRB for 25% off (of $95)
  18. Consider coming to our non-profit JavaScript Craftsmanshop next week in

    Denver @ Uncubed on 9/8 & 9/9 register at http://is.gd/jasmine Use coupon code RMRB for 25% off (of $95) 2 days for 71-ish dollars
  19. thank you! [email protected] Rocky Mountain Ruby, Boulder, CO September 2,

    2011 @searls seefl[email protected] @seeflanigan Thanks to Brandon Keepers (@bkeepers) for the Keynote template! find this talk at http://is.gd/rockyjasmine