Jasmine 2 cheat sheet for RSpec lamers

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

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')
Henning Koch Over 9 years ago