Fun facts about Jasmine

Wat
Wat

Let's start again...

Pass

Some (Real) Jasmine Facts

By the way...

Pivotal CI (publicly visible!)

Fail

So how is our old friend Hudson?

* Yes, I know it's Jenkins now...

Fail

Game over, man! Game over!

Fail

Why bother testing?

Wat

Let's review!

JavaScript is code. Therefore: let's unit-test it.

Sean Handley (about 2 seconds ago)

Installing Jasmine

Gemfile


      ...
      gem 'jasmine'
      ...
    

Run


      $ bundle install
      $ jasmine init
    

Anatomy

/spec


    + spec/
      + javascripts/
        + fixtures/
          - awesome.html
        + helpers/
          - jasmine-jquery.js
        - my_awesome_page_spec.js
        + support/
          - jasmine.yml
          - jasmine_config.rb
          - jasmine_runner.rb
    

Anatomy

jasmine.yml

  src_files:
    - public/javascripts/jquery.min.js
    - public/javascripts/my_awesome_page.js

  stylesheets:
    - stylesheets/**/*.css

  helpers:
    - helpers/jasmine-jquery.js

  spec_files:
    - '**/*[sS]pec.js'

  src_dir: '/'

  spec_dir: spec/javascripts
    

Running your tests

On Dev Machine


      $ rake jasmine # launches server
    

On CI Server


      $ rake jasmine:ci # launches tests as a non-interactive job
    

Ok! Codez!

spec/javascripts/my_awesome_page_spec.js

  describe("my_awesome_page", function() {

    beforeEach(function() {
      loadFixtures("awesome.html");
    });

    describe("#change_status(status)", function() {
      it("should change the status message", function() {
        expect($('div#awesome').text()).toNotEqual("Awesome!");
        change_status('Awesome!');
        expect($('div#awesome').text()).toEqual("Awesome!");
      });
    });
  });
      

Code fail!

http://localhost:8888

Fail

Ok! Moar codez!

spec/javascripts/fixtures/awesome.html

  <div id="awesome"></div>
      

public/javascripts/my_awesome_page.js

  function change_status(status){
    $('div#awesome').append(status);
  }
      

Code pass!

http://localhost:8888

Pass

Cool things

Questions???

Pass

/