tea-time/presentation/07_matchers.slides

61 lines
938 B
Plaintext
Raw Permalink Normal View History

2012-03-13 17:29:42 +00:00
!SLIDE
# Matchers
!SLIDE even-larger
``` ruby
cat.meow.should == "meow"
cat.should be_a_kind_of(Cat)
2012-03-22 13:48:09 +00:00
cat.should_not be_hungry
# => cat.hungry?.should == false
2012-03-13 17:29:42 +00:00
```
!SLIDE even-larger
``` coffeescript
expect(cat.meow()).toEqual("meow")
2012-03-24 14:20:56 +00:00
expect(cat.constructor).toEqual(Cat)
2012-03-13 17:29:42 +00:00
expect(cat.isHungry()).not.toBeTruthy()
```
!SLIDE even-larger
# Lots of built in matchers
``` coffeescript
toEqual(object)
toBeTruthy()
toBeFalsy()
toBeGreaterThan()
toBeLessThan()
toBeUndefined()
toContain()
toMatch()
```
!SLIDE even-larger
``` coffeescript
expect(cat.isHungry()).not.toBeTruthy()
```
!SLIDE
# Create your own matchers!
!SLIDE even-larger
``` coffeescript
MyMatchers =
toBeHungry: ->
return @actual.isHungry() == true
beforeEach ->
this.addMatchers(MyMatchers)
2012-03-24 14:20:56 +00:00
```
2012-03-13 17:29:42 +00:00
2012-03-24 14:20:56 +00:00
!SLIDE even-larger
``` coffeescript
2012-03-13 17:29:42 +00:00
describe 'Cat', ->
beforeEach ->
@cat = new Cat()
it 'should not be hungry', ->
expect(@cat).not.toBeHungry()
```