Read more

Jasmine 2 cheat sheet for RSpec lamers

Henning Koch
January 18, 2015Software engineer at makandra GmbH

In the tradition of our PostgreSQL cheat sheet for MySQL lamers, here is a cheat sheet for Jasmine when you're used to RSpec.

Illustration book lover

Growing Rails Applications in Practice

Check out our e-book. Learn to structure large Ruby on Rails codebases with the tools you already know and love.

  • Introduce design conventions for controllers and user-facing models
  • Create a system for growth
  • Build applications to last
Read more Show archive.org snapshot

Note that Jasmine syntax has changed with Jasmine 2, so if you're using Jasmine 1.x you might instead want to use an older cheat sheet Show archive.org snapshot .

Expectations

# RSpec
expect(foo).to.eq("value")
expect(foo).to_not eq("value")

# Jasmine
expect(foo).toBe("value")
expect(foo).not.toBe("value")

Mocks

# RSpec
expect(foo).to_receive(:method).twice.with('arg').and_return('value')

# Jasmine
spyOn(foo, 'method').and.returnValue('value')
expect(foo.calls.count()).toBe(2)
expect(foo.method).toHaveBeenCalledWith('arg')
Posted by Henning Koch to makandra dev (2015-01-18 17:09)