Successfully reported this slideshow.
Your SlideShare is downloading. ×

Testing Javascript with Jasmine

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Loading in …3
×

Check these out next

1 of 88 Ad

Testing Javascript with Jasmine

Download to read offline

Slides from my Lonestar Ruby Conf 2011 presentation.

*** Video of presentation: http://confreaks.com/videos/2531-lsrc2011-testing-javascript-with-jasmine ***

Agenda:
- Briefly cover why you should unit test
- Discuss what Jasmine is and isn't
- Show syntax with comparisons to RSpec
- Jasmine with:
- Vanilla JavaScript
- Jasmine with jQuery
- Jasmine with Ruby (not Rails)
- Jasmine with Rails
- Evergreen
- capybara-webkit
- Where does CoffeeScript, node.js, etc. fit in?
- Other helpful libraries/Wrap-up

Slides from my Lonestar Ruby Conf 2011 presentation.

*** Video of presentation: http://confreaks.com/videos/2531-lsrc2011-testing-javascript-with-jasmine ***

Agenda:
- Briefly cover why you should unit test
- Discuss what Jasmine is and isn't
- Show syntax with comparisons to RSpec
- Jasmine with:
- Vanilla JavaScript
- Jasmine with jQuery
- Jasmine with Ruby (not Rails)
- Jasmine with Rails
- Evergreen
- capybara-webkit
- Where does CoffeeScript, node.js, etc. fit in?
- Other helpful libraries/Wrap-up

Advertisement
Advertisement

More Related Content

Slideshows for you (20)

Advertisement

Recently uploaded (20)

Advertisement

Testing Javascript with Jasmine

  1. 2. Testing JavaScript with Jasmine By: Tim Tyrrell
  2. 3. Tim Tyrrell @timtyrrell    
  3. 4. Agenda <ul><li>- Briefly cover why you should unit test </li></ul><ul><li>- Discuss what Jasmine is and isn't </li></ul><ul><li>- Show syntax with comparisons to RSpec </li></ul><ul><li>- Jasmine with: </li></ul><ul><li>    - Vanilla JavaScript </li></ul><ul><li>    - Jasmine with jQuery </li></ul><ul><li>    - Jasmine with Ruby (not Rails) </li></ul><ul><li>    - Jasmine with Rails </li></ul><ul><li>    - Evergreen </li></ul><ul><li>    - capybara-webkit </li></ul><ul><li>- Where does CoffeeScript, node.js, etc. fit in? </li></ul><ul><li>- Other helpful libraries/Wrap-up </li></ul>
  4. 5. Why are you talking about JavaScript at a  Ruby conference?
  5. 6. Why unit test JavaScript?
  6. 7. &quot;External tests don't help us with internal design&quot; @glv
  7. 8. &quot;There is only one way to go truly fast. Do the best job you can. Anything else is slower.&quot; @unclebobmartin http://twitter.com/#!/unclebobmartin/status/39438225869254656
  8. 10. What is Jasmine?
  9. 11. Why Jasmine?
  10. 12. Jasmine is not an integration testing framework.
  11. 13. RSpec vs. Jasmine: Structure #RSpec describe &quot;Calculate&quot; do      describe &quot;#add&quot; do          it &quot;should return the sum&quot; do              ...          end      end end //Jasmine describe &quot;Calculate&quot;, function(){      describe &quot;#Add&quot;, function(){          it &quot;should return the sum&quot;, function(){          ...          };      }); });
  12. 14. RSpec vs. Jasmine: Before/After #RSpec before(:each) do           @calc = Calculator.new  end    after(:each) do           @calc.reset  end //Jasmine var calc;  beforeEach(function(){     calc = new Calculator(); });    afterEach(function(){     calc.reset();  });
  13. 15. RSpec vs. Jasmine: Expectations # RSpec  it &quot;should return the sum&quot; do       calc = Calculator.new        calc.add(1,1).should == 2     calc.add(1,2).should_not == 2 #Use one expectation per 'it'! end   // Jasmine  it(&quot;should return the sum&quot;, function() {           var calc = new Calculator();       expect(calc.Add(1,1)).toEqual(2);     expect(calc.Add(1,2)).not.toEqual(2); //Use one expectation per 'it'!  });
  14. 16. Jasmine Matchers expect(x).toEqual(y)   expect(x).toBe(y);   expect(x).toMatch(pattern) expect(x).toBeDefined() expect(x).toBeNull();   expect(x).toBeTruthy(); expect(x).toBeFalsy(); expect(x).toContain(y); expect(x).toBeLessThan(y); expect(x).toBeGreaterThan(y); expect(fn).toThrow(e);
  15. 17. Custom Matchers <ul><li>#RSpec </li></ul><ul><li>Spec::Matchers.define :be_greater_than_zero do </li></ul><ul><li>  match do |actual| </li></ul><ul><li>    actual > 0 </li></ul><ul><li>  end </li></ul><ul><li>end </li></ul><ul><li>Spec::Matchers.define :be_zero_when_subtracting do </li></ul><ul><li>  match do |actual, number| </li></ul><ul><li>    (actual - number) == 0 </li></ul><ul><li>  end </li></ul><ul><li>end </li></ul>
  16. 18. Custom Matchers <ul><li>// Jasmine </li></ul><ul><li>beforeEach(function() { </li></ul><ul><li>  this.addMatchers({ </li></ul><ul><li>    toBeGreaterThanZero: function() { </li></ul><ul><li>      return this.actual > 0; </li></ul><ul><li>    } </li></ul><ul><li>  }), </li></ul><ul><li>  this.addMatchers({ </li></ul><ul><li>    toBeZeroWhenSubtracting: function(number) { </li></ul><ul><li>      return (this.actual - number) === 0 </li></ul><ul><li>    } </li></ul><ul><li>  }) </li></ul><ul><li>}); </li></ul>
  17. 19. Custom Matchers <ul><li>describe('Custom Matchers', function () { </li></ul><ul><li>  it('should be greater than 0', function () { </li></ul><ul><li>    expect(1).toBeGreaterThanZero(); </li></ul><ul><li>  }); </li></ul><ul><li>  it('should equal zero when subtracting two numbers', function() { </li></ul><ul><li>    expect(5).toBeZeroWhenSubtracting(5); </li></ul><ul><li>  }); </li></ul><ul><li>}); </li></ul>
  18. 20. RSpec vs. Jasmine: Stubbing # RSpec  it &quot;should add the numbers&quot; do       calc = Calculator.new       calc.stub!(:add).and_return(3)       calc.add(1,1).should == 3 end  // Jasmine  it(&quot;should add the numbers&quot;, function() {       var calc = new Calculator();       spyOn(calc, 'add').andReturn(3);      expect(calc.Add(1,1)).toEqual(3);  });
  19. 21. TDD? &quot; Red , Green , Refactor&quot;
  20. 22. Why do *I* like TDD?
  21. 23. Jasmine with &quot;vanilla&quot; JavaScript <ul><li>- Download &quot;Stand alone&quot;  </li></ul><ul><li>  </li></ul><ul><li>http://pivotal.github.com/jasmine/download.html </li></ul>
  22. 28. describe(&quot;Calculator&quot;, function() {    }); Spec for Calculator:
  23. 29. describe(&quot;Calculator&quot;, function() {   var calc;   beforeEach(function(){     calc = new Calculator();   }); }); Spec for Calculator:
  24. 30. describe(&quot;Calculator&quot;, function() {   var calc;   beforeEach(function(){     calc = new Calculator();   }); }); Spec for Calculator:
  25. 31. describe(&quot;Calculator&quot;, function() {   var calc;   beforeEach(function(){     calc = new Calculator();   });   it(&quot;should return the sum&quot;, function() {     expect(calc.Add(1,1)).toEqual(2);   }); }); Spec for Calculator:
  26. 32. Failing Test
  27. 33. Create the &quot;Calculator&quot; function <ul><li>function Calculator () { </li></ul><ul><li>} </li></ul>
  28. 34. One passing, one left to fix
  29. 35. Add the method <ul><li>function Calculator () {   this.Add = function(num1, num2){     return num1 + num2;   }; } </li></ul>
  30. 36. Passed!
  31. 37. Jasmine with Ruby(not Rails)
  32. 38. $ gem install jasmine
  33. 39. $ jasmine init
  34. 40. Generated folder structure
  35. 41. $ rake jasmine
  36. 42. http://localhost:8888
  37. 43. $ rake jasmine:ci
  38. 44. Jasmine with JQuery
  39. 45.      * toBe(jQuerySelector)     * toBeChecked()     * toBeEmpty()     * toBeHidden()     * toBeSelected()     * toBeVisible()     * toContain(jQuerySelector)     * toExist()     * toHaveAttr(attributeName, attributeValue)     * toHaveBeenTriggeredOn(selector)     * toHaveClass(className)     * toHaveData(key, value)     * toHaveHtml(string)     * toHaveId(id)     * toHaveText(string)     * toHaveValue(value)     * toBeDisabled() jasmine-jquery Matchers
  40. 46. &quot;A lightweight, easy to use Javascript <span> injector for radical Web Typography&quot;
  41. 47. @davatron5000
  42. 48. Lettering.js <h1 class=&quot;fancy_title&quot;>Some Title</h1> <script>   $(document).ready(function() {     $(&quot;.fancy_title&quot;).lettering();   }); </script>
  43. 49. Lettering.js results <ul><li><h1 class=&quot;fancy_title&quot;> </li></ul><ul><li>  <span class=&quot;char1&quot;>S</span> </li></ul><ul><li>  <span class=&quot;char2&quot;>o</span> </li></ul><ul><li>  <span class=&quot;char3&quot;>m</span> </li></ul><ul><li>  <span class=&quot;char4&quot;>e</span> </li></ul><ul><li>  <span class=&quot;char5&quot;></span> </li></ul><ul><li>  <span class=&quot;char6&quot;>T</span> </li></ul><ul><li>  <span class=&quot;char7&quot;>i</span> </li></ul><ul><li>  <span class=&quot;char8&quot;>t</span> </li></ul><ul><li>  <span class=&quot;char9&quot;>l</span> </li></ul><ul><li>  <span class=&quot;char10&quot;>e</span> </li></ul><ul><li></h1> </li></ul>
  44. 50. Standalone folder structure + more
  45. 51. <ul><li><!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot; </li></ul><ul><li>  &quot;http://www.w3.org/TR/html4/loose.dtd&quot;> </li></ul><ul><li><html> </li></ul><ul><li><head> </li></ul><ul><li>  <title>Jasmine Test Runner</title> </li></ul><ul><li>  <link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;lib/jasmine-1.0.2/jasmine.css&quot;> </li></ul><ul><li>  <script type=&quot;text/javascript&quot; src=&quot;lib/jasmine-1.0.2/jasmine.js&quot;></script> </li></ul><ul><li>  <script type=&quot;text/javascript&quot; src=&quot;lib/jasmine-1.0.2/jasmine-html.js&quot;></script> </li></ul><ul><li>  <script type=&quot;text/javascript&quot; src=&quot;lib/jquery-1.6.1.min.js&quot;></script> </li></ul><ul><li>  <script type=&quot;text/javascript&quot; src=&quot;lib/jasmine-jquery-1.2.0.js&quot;></script> </li></ul><ul><li>  <script type=&quot;text/javascript&quot; src=&quot;lib/jquery.lettering-0.6.1.min.js&quot;></script> </li></ul><ul><li>  <script type=&quot;text/javascript&quot; src=&quot;spec/LetteringSpec.js&quot;></script> </li></ul><ul><li></head> </li></ul><ul><li><body> </li></ul><ul><li><script type=&quot;text/javascript&quot;> </li></ul><ul><li>  jasmine.getEnv().addReporter(new jasmine.TrivialReporter()); </li></ul><ul><li>  jasmine.getEnv().execute(); </li></ul><ul><li></script> </li></ul><ul><li></body> </li></ul><ul><li></html> </li></ul>
  46. 52. <ul><li>describe(&quot;Lettering&quot;, function(){ </li></ul><ul><li>  beforeEach(function(){ </li></ul><ul><li>    //loadFixtures('myfixture.html'); </li></ul><ul><li>    setFixtures('<h1 class=&quot;fancy_title&quot;>Some Title</h1>'); </li></ul><ul><li>    $('.fancy_title').lettering(); </li></ul><ul><li>  }); </li></ul><ul><li>}); </li></ul>
  47. 53. <ul><li>describe(&quot;Lettering&quot;, function(){ </li></ul><ul><li>  beforeEach(function(){ </li></ul><ul><li>    //loadFixtures('myfixture.html'); </li></ul><ul><li>    setFixtures('<h1 class=&quot;fancy_title&quot;>Some Title</h1>'); </li></ul><ul><li>    $('.fancy_title').lettering(); </li></ul><ul><li>  }); </li></ul><ul><li>  it(&quot;should be visible&quot;, function() { </li></ul><ul><li>    expect($('.fancy_title')).toBeVisible(); </li></ul><ul><li>  }); </li></ul><ul><li>}); </li></ul>
  48. 54. <ul><li>describe(&quot;Lettering&quot;, function(){ </li></ul><ul><li>  beforeEach(function(){ </li></ul><ul><li>    //loadFixtures('myfixture.html'); </li></ul><ul><li>    setFixtures('<h1 class=&quot;fancy_title&quot;>Some Title</h1>'); </li></ul><ul><li>    $('.fancy_title').lettering(); </li></ul><ul><li>  }); </li></ul><ul><li>  it(&quot;should be visible&quot;, function() { </li></ul><ul><li>    expect($('.fancy_title')).toBeVisible(); </li></ul><ul><li>  }); </li></ul><ul><li>  it(&quot;should have 10 spans&quot;, function(){ </li></ul><ul><li>    expect($('.fancy_title > span').length).toEqual(10); </li></ul><ul><li>  }); </li></ul><ul><li>}); </li></ul>
  49. 55. <ul><li>describe(&quot;Lettering&quot;, function(){ </li></ul><ul><li>  beforeEach(function(){ </li></ul><ul><li>    //loadFixtures('myfixture.html'); </li></ul><ul><li>    setFixtures('<h1 class=&quot;fancy_title&quot;>Some Title</h1>'); </li></ul><ul><li>    $('.fancy_title').lettering(); </li></ul><ul><li>  }); </li></ul><ul><li>  it(&quot;should be visible&quot;, function() { </li></ul><ul><li>    expect($('.fancy_title')).toBeVisible(); </li></ul><ul><li>  }); </li></ul><ul><li>  it(&quot;should have 10 spans&quot;, function(){ </li></ul><ul><li>    expect($('.fancy_title > span').length).toEqual(10); </li></ul><ul><li>  }); </li></ul><ul><li>  it(&quot;should contain 'S' as the text of the first span&quot;, function(){ </li></ul><ul><li>    expect($('.fancy_title > span:first').text()).toEqual('S'); </li></ul><ul><li>  }); </li></ul><ul><li>}); </li></ul>
  50. 56. <ul><li>describe(&quot;Lettering&quot;, function(){ </li></ul><ul><li>  beforeEach(function(){ </li></ul><ul><li>    //loadFixtures('myfixture.html'); </li></ul><ul><li>    setFixtures('<h1 class=&quot;fancy_title&quot;>Some Title</h1>'); </li></ul><ul><li>    $('.fancy_title').lettering(); </li></ul><ul><li>  }); </li></ul><ul><li>  it(&quot;should be visible&quot;, function() { </li></ul><ul><li>    expect($('.fancy_title')).toBeVisible(); </li></ul><ul><li>  }); </li></ul><ul><li>  it(&quot;should have 10 spans&quot;, function(){ </li></ul><ul><li>    expect($('.fancy_title > span').length).toEqual(10); </li></ul><ul><li>  }); </li></ul><ul><li>  it(&quot;should contain 'S' as the text of the first span&quot;, function(){ </li></ul><ul><li>    expect($('.fancy_title > span:first').text()).toEqual('S'); </li></ul><ul><li>  }); </li></ul><ul><li>  it(&quot;should have a class of 'char1' on the first span&quot;, function(){ </li></ul><ul><li>    expect($('.fancy_title > span:first')).toHaveClass('char1'); </li></ul><ul><li>  }); </li></ul><ul><li>}); </li></ul>
  51. 57. Jasmine with Rails gem &quot;jasmine&quot;  $ bundle install $ jasmine init (optional) $ rake jasmine or  $ rake jasmine:ci http://localhost:8888
  52. 58. Generated Rails spec folder
  53. 59. Generated default javascript objects
  54. 60. $ rake jasmine 
  55. 62. $ gem install evergreen
  56. 63. gem install evergreen
  57. 64. Evergreen default folder paths  (not generated)
  58. 65. $ evergreen serve
  59. 66. $ evergreen run
  60. 67. Evergreen and Rails 3 <ul><li>gem 'evergreen', :require => evergreen/rails'localhost:3000/evergreen </li></ul><ul><li>rake spec:javascripts </li></ul>
  61. 68. What about CoffeeScript???
  62. 69. Installing CoffeeScript <ul><li>brew install node.js (then add to PATH, NODE_PATH) </li></ul><ul><li>curl http://npmjs.org/install.sh | sh </li></ul><ul><li>npm install -g coffee-script </li></ul>
  63. 70. Add  a &quot;_spec.coffee&quot; file
  64. 71. <ul><li>require('/calculator.js') </li></ul><ul><li>describe 'Calculator', -> </li></ul><ul><li>  beforeEach -> </li></ul><ul><li>    @calc = new Calculator </li></ul><ul><li>  it 'should return the sum', -> </li></ul><ul><li>    expect(@calc.Add(1,1)).toEqual(2) </li></ul>
  65. 72. <ul><li>require('/calculator.js') </li></ul><ul><li>describe 'Calculator', -> </li></ul><ul><li>  beforeEach -> </li></ul><ul><li>    @calc = new Calculator </li></ul><ul><li>  it 'should return the sum', -> </li></ul><ul><li>    expect(@calc.Add(1,1)).toEqual(2) </li></ul>
  66. 73. <ul><li>require('/calculator.js') </li></ul><ul><li>describe 'Calculator', -> </li></ul><ul><li>  beforeEach -> </li></ul><ul><li>    @calc = new Calculator </li></ul><ul><li>  it 'should return the sum', -> </li></ul><ul><li>    expect(@calc.Add(1,1)).toEqual(2) </li></ul>
  67. 74. #winning
  68. 76. Headless Browser Install <ul><li>- Download and install Qt 4.7+ binary package </li></ul><ul><li>- gem install capybara-webkit -v=1.0.0.beta4 </li></ul><ul><li>- create &quot;config/evergreen.rb&quot; </li></ul>
  69. 77. Configure Evergreen <ul><li>require 'capybara-webkit' </li></ul><ul><li>Evergreen.configure do |config| </li></ul><ul><li>  #config.driver = :selenium </li></ul><ul><li>  config.driver = :webkit </li></ul><ul><li>  config.public_dir = 'public' </li></ul><ul><li>  config.spec_dir = 'spec/javascripts' </li></ul><ul><li>end </li></ul>
  70. 78. Using a Headless Browser <ul><li>#selenium </li></ul><ul><li>Finished in 3.92 seconds </li></ul><ul><li>2 examples, 0 failures </li></ul><ul><li>#webkit </li></ul><ul><li>Finished in 1.05 seconds </li></ul><ul><li>2 examples, 0 failures </li></ul>
  71. 79. Node.js + Jasmine <ul><li>&quot;jasmine-node&quot; </li></ul>
  72. 80. Any other cool utilities?
  73. 81. Rosie <ul><li>&quot; Rosie is a factory for building JavaScript objects, mostly useful for setting up test data. It is inspired by  factory_girl . &quot; </li></ul><ul><li>https://github.com/bkeepers/rosie </li></ul>
  74. 82. Summer Breeze <ul><li>&quot; Summer Breeze is a tool for generating fixture DOM output for Jasmine JavaScript tests directly from your Rails Views with a simple DSL for specifying fixtures &quot; </li></ul><ul><li>https://github.com/noelrappin/summer_breeze </li></ul>
  75. 83. jasminerice <ul><li>&quot;Pain free coffeescript testing under Rails 3.1&quot; </li></ul><ul><li>https://github.com/bradphelan/jasminerice </li></ul>
  76. 84. http://try-jasmine.heroku.com
  77. 85. Wrap Up <ul><li>1. Unit testing is important </li></ul><ul><li>2. Javascript can and should be unit tested </li></ul><ul><li>3. Jasmine is easy to setup and use </li></ul>
  78. 87. Thank You! @timtyrrell Questions? Did I miss any cool plugins? http://bit.ly/jasmine-lsrc http://spkr8.com/t/7818
  79. 88. http://pivotal.github.com/jasmine/ https://github.com/jnicklas/evergreen https://github.com/velesin/jasmine-jquery https://github.com/thoughtbot/capybara-webkit http://obtiva.com/blog/112-javascript-specs-with-jasmine-a-primer-for-rubyists-part-1 http://obtiva.com/blog/119 http://daverupert.com/2010/09/lettering-js/ http://www.engineyard.com/university/screencasts/javascript-tests-with-jasmine http://blog.levid.com/?p=29 http://blog.carbonfive.com/2010/10/21/rspec-best-practices/ https://github.com/johnbintz/guard-jasmine-headless-webkit References:

Editor's Notes

  • Tim Tyrrell, from Chicago, moved to Austin a year and a half ago. I work as a Rails Developer at PeopleAdmin in Austin, TX.  We have a SaaS talent management application with about 700 customers in the higher education, government, and non-profit sectors. Post jobs, apply to jobs, hiring workflows, etc.
  • I appreciate you attending my session. I know that you have a choice today on which session to attend, so I plan to make a good use of your time. In accordance, I want to set your expectations by displaying my agenda. It is pretty slide heavy talk with lots of different code examples, but we will blow through them, so don&apos;t let that scare you. I know that I am what is standing between you and chicken fried chicken, so I will tread lightly here. This is an intro to testing with jasmine. Cover a lot of stuff briefly. So if you have ever worked with Jasmine, you may want to bail right now.
  • - A lot of us use Ruby through Rails or Sinatra, so we have views, and these views use javascript. - I know that it is a gap in most applications. I think that is is something that might be scary but I want to show you that we can fill this gap and it is not very difficult. Although, it will take a mindset change.
  • - it is code! - it can be very complex! -There was a time where it was though of as a toy language, but that misconception has obviously been blown away. -What is the problem? I think it&apos;s viewed like the wild wild west. You write a bunch of procedural script inside the views and any thought of testing code like that is impossible. Procedural  non-modular code, is horribly difficult to test. so right off the bat, you need to treat your javascript code with respect and care that you may backend code. Other perceived problems? Testing javascript is hard to get setup. - Why now? With javascript being more of an important piece of our software, with all this focus shifting to javascript, we need to do it right. Unit testing is the right way to do it. 
  • - I know people say testing slows you down, but the reality is, a deployment that fails is going to slow you down. Refactoring some code and breaking half your application is going to slow you down. - yes, there are such things as spikes and prototypes where testing doesn&apos;t make sense. - what Obie said - testing is not easy. A know a number of folks in this room that have been doing it for 5+ years, and they are still learning new things and changing their opinions on the best way to do things. 
  • Don&apos;t be this guy. You don&apos;t have to test-drive it, but you need to test it. The like unit testing because I don&apos;t want to get paged in the middle of the night.
  • - Created by Pivitol Labs - there are other JS testing frameworks: QUnit is the most obvious one, which is used by the jQuery project. QUnit is more of a standard assertion framework where as Jasmine has the BDD style-syntax
  • - super easy to get going and is super easy to use with Rails - Familiar RSpec Syntax (context switching is a killer) - It has a RubyGem for Ruby, Rails, or even Node.js. Also, you can use it without Ruby. - Easy to plug into a CI server, headless or not - Does not require the DOM - It does not depend on any other javascript frameworks - big community around it. Lot&apos;s of plugins and it is being pushed
  • - This is for testing javascript in isolation. &amp;quot;Unit testing&amp;quot;   - More like Test::Unit or RSpec, JUnit, NUnit, etc.   - Not Cucumber, Capybara, etc.
  • Differences? - With Rspec I could remove the double-quotes from &amp;quot;Calculate&amp;quot; and it will new that object up for us as the subject. - Rspec uses blocks and Jasmine uses anonymous functions - RSpec allows you to switch out the word describe for context and also there is some other syntactical magic you can us, Jasmine is straight forward.
  • Differences? - this is the setup/teardown events - you can declare @calc in the before block in RSpec and it will be available in other blocks. Not so with Jasmine.
  • - RSpec has different methods that define expectations, but Jasmine only has &amp;quot;expect&amp;quot; which is passed an argument and then chained with matchers. - To test negation you just chain on a &amp;quot;not&amp;quot; - Noel and the one assertion per &amp;quot;it&amp;quot;
  • spec_helper.rb
  • #spec helper.js
  • - A &amp;quot;onSpy&amp;quot; call will remove the specified function from the object and replace it with a spy. This spy will absorb all calls to that method and you can optionally chain a return method on to it.
  • - Test-Driven Development Write a failing test, make it pass, then make it better. Write a test before you write the code to make it pass. I will cover this quickly, it is something we have all heard a million times(I hope!). 
  • - Attention span- Keeps me focused on one thing at a time. If I have a failing test, I know exactly what I am working on and will not bounce off onto a tangent or down a rabbit hole.   - Helps you design your API, because you are utilizing it for your tests - Helps me sleep at night. I can deploy and not be scared to death that something will break. - Keeps me moving fast. Make a change, run the tests, move on. Don&apos;t need to open the browser and click. - Give me confidence in major refactorings. (Same as above)
  • - TDD manner!!!
  • - open the html in a browser
  • -  gem &apos;jasmine&apos; if bundler
  • - create a folder
  • - check out the default specs and functions - explain conventions. *Spec.js
  • - fire up the web server
  • - obviously used with Continuous Integration server. Selenium is run, browser opens closes, etc. - run it in the background while you work
  • Jasmine has a number of libraries, one of them deals with jQuery a set of custom matchers for jQuery framework an API for handling HTML fixtures in your specs
  • dom matchers, not object matchers
  • - find grained control of your text - if you are going to refactor your code or add more features, you don&apos;t want to break anything. You need to pin down you existing functionality to keep yourself moving fast.
  • Added a couple libraries and also a fixture directory.
  • - no ruby required here
  • - set the HTML or load a fixture from spec/javascripts - clears it after each run
  • - using a jQuery selecting in the expect matcher
  • - pinning down functionality
  • Also you can rake jasmine:ci Dr. Phil next.
  • Alright, that was the normal Jasmine way to get things set it. It is easy. But, it can be a little easier. There is a better way.
  • Best of breed. Templates, no generators, and coffeescript support. Defaults with Selenium, but you can rock it with Capybara, whatever - not a stand alone, you need ruby (obviously)
  • - folder conventions
  • - CoffeeScript next - recap
  • install node.js install npm install coffeescript
  • - no different than the other evergreen usage of calculator_spec.js
  • side by side.
  • - this is how I felt after I did that. so what did I do? 1. installed the evergreen gem 2. mimicked a folder structure 3. added a file of a coffee extension
  • capybara-webkit depends on a WebKit implementation from Qt, a cross-platform development toolkit. jasmine-headless-webkit uses the QtWebKit widget to run your specs without needing to render a pixel. It&apos;s nearly as fast as running in a JavaScript engine like Node.js, and, since it&apos;s a real browser environment, all the modules you would normally use, like jQuery and Backbone, work without any modifications.
  • - guard-jasmine-headless-webkit
  • - big problems - you get to work with me
  • THANKS FOR LISTENING! It is easy to setup and use, and it will help you sleep better at night. Grow a neck beard.

×