tea-time/presentation/05_meow_states.slides

118 lines
2.1 KiB
Plaintext
Raw Normal View History

2012-03-13 17:29:42 +00:00
!SLIDE
# What if the cat meows differently based on certain states?
!SLIDE image-80-percent
<img src="assets/hungry-cat.jpg" />
!SLIDE image-80-percent
<img src="assets/cat-carrier.jpg" />
!SLIDE
# Nested `describe`
!SLIDE larger
``` coffeescript
describe 'Cat', ->
describe '#meow', ->
describe 'hungry', ->
2012-03-22 13:48:09 +00:00
# Cat#meow expectation for when
# the cat is hungry
2012-03-13 17:29:42 +00:00
describe 'going to the vet', ->
2012-03-22 13:48:09 +00:00
# Cat#meow expectation for when
# the cat knows it's vet time
2012-03-13 17:29:42 +00:00
```
!SLIDE larger
``` coffeescript
describe 'Cat', ->
describe '#meow', ->
describe 'hungry', ->
it 'should be a mournful meow', ->
cat = new Cat()
2012-03-22 13:48:09 +00:00
cat.state = -> Cat.HUNGRY
# ...just like cat.stubs(:state)
2012-03-13 17:29:42 +00:00
expect(cat.meow()).toEqual("meeeyaow")
describe 'going to the vet', ->
it 'should be an evil meow', ->
cat = new Cat()
2012-03-22 13:48:09 +00:00
cat.state = -> Cat.VET_PSYCHIC
# ...just like the one above
2012-03-13 17:29:42 +00:00
expect(cat.meow()).toEqual("raowwww")
```
!SLIDE image-80-percent
<img src="assets/wet-cat.jpg" />
!SLIDE even-larger
``` coffeescript
cat = new Cat()
```
!SLIDE even-larger
``` ruby
before do
@cat = Cat.new
end
it 'should be a mournful meow' do
@cat.stubs(:state).returns(Cat::HUNGRY)
@cat.meow.should == "meeyaow"
end
```
!SLIDE even-larger
``` ruby
before -> it -> after
```
!SLIDE even-larger
``` ruby
before do
@instance_variable = "yes"
end
2012-03-22 13:48:09 +00:00
it "is in same context as before block" do
2012-03-13 17:29:42 +00:00
@instance_variable.should == "yes"
end
```
!SLIDE even-larger
``` coffeescript
beforeEach -> it -> afterEach
```
!SLIDE even-larger
``` coffeescript
beforeEach ->
@instanceVariable = "yes"
it "should be in the same context", ->
expect(@instanceVariable).toEqual("yes")
```
!SLIDE larger
``` coffeescript
describe 'Cat', ->
describe '#meow', ->
beforeEach ->
@cat = new Cat()
describe 'hungry', ->
it 'should be a mournful meow', ->
@cat.state = -> Cat.HUNGRY
expect(@cat.meow()).toEqual("meeeyaow")
describe 'going to the vet', ->
it 'should be an evil meow', ->
@cat.state = -> Cat.VET_PSYCHIC
expect(@cat.meow()).toEqual("raowwww")
```