Fast Rails Tests

Rails: Extracting Domain Objects

class SomeController
  def show
    get_result(params[:options])
  end

  private
  def get_result(options)
    options[:name] + ' ' + options[:age]
  end
end

Rails: Extracting Domain Objects

class ResultModel
  def self.get_result(options)
    options[:name] + ' ' + options[:age]
  end
end

...
def show
  ResultModel.get_result(params[:options])
end

Rails: Avoiding Extra Work

Rails: Avoid spec_helper

Rails: Choose Factories Carefully

Rails: Fast Tests!

Jasmine: Process

Jasmine: Structure

describe(function(){
  beforeEach(function(){
    this.deal = 'Old Navy Stuff';
  });

  it(function(){
    //test!
    this.deal === 'Old Navy Stuff';
  });
});

Jasmine: Mocking and Spies

describe("mocking Dates", function(){
  it("can mock global.Date", function(){
    this._Date = Date;
    var testContext = this;

    spyOn(global, 'Date').andCallFake(function(){
      return new testContext._Date(1999, 4, 8);
    });

    var raw = new Date();
    var old = new this._Date(1900, 10, 10);

    expect(raw.getFullYear()).not.toEqual(old.getFullYear());
  });
});

Jasmine: Fixtures

var frag = fixtures['filename no extension'];
$('#jasmine-content').append(frag);

Jasmine: Live Events and Callable Bindings

$('.cards').live('click', function(){
  //handle event
});

/* */

function bindEvents() {
  $('.cards').live('click', function(){
    //handle event
  });
}

Metrics

#

/