Skip to content

Instantly share code, notes, and snippets.

@searls
Created November 16, 2011 04:20
Show Gist options
  • Save searls/1369224 to your computer and use it in GitHub Desktop.
Save searls/1369224 to your computer and use it in GitHub Desktop.
jasmine-given example
class MakesSandwiches
make: -> cheese: "swiss", bread: "sourdough"
#jasmine-given
describe "MakesSandwiches", ->
Given -> @subject = new MakesSandwiches
describe "#make", ->
When -> @sandwich = @subject.make()
Then -> expect(@sandwich).toHave("bread")
Then -> expect(@sandwich).toHave("cheese")
#vanilla jasmine
describe "MakesSandwiches", ->
beforeEach ->
@subject = new MakesSandwiches
describe "#make", ->
beforeEach ->
@sandwich = @subject.make()
it "has bread", ->
expect(@sandwich).toHave("bread")
it "has cheese", ->
expect(@sandwich).toHave("cheese")
#a custom matcher for toHave()'ing properties.
beforeEach ->
@addMatchers
toHave: (property) ->
@actual.hasOwnProperty(property)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment