Rubyconf China 2012
View Slide
whoami
太檑
Terry
@poshboytl
Co-founder ofPragmatic.ly
Creator ofRailscasts-china.com
Survey
How many peoplewrite tests?
How many people useRSpec?
Tools we use
I love RSpec!
Bad boy!
x.should == y
Straightforward!
asset_equal y, x
This is just right!
Pillow War!
Peace! Choose whatyou like!
Try it, instead offollowing anybody.
Syntax
SyntaxSugar
SyntaxSugarDSL
Is syntax important?
Syntax is important, that’s themost important reason why welove Ruby! It also can be thereason we love RSepc!
Syntax is important, that’s themost important reason why welove Ruby! It also can be thereason we love RSepc!Terry Tai
Let’s talk about RSpec!
Our practices
Setup phase contains two partsuse ‘let’ to initialize data‘before’ block to do some actions
Why straightforward isimportant for us?
The sugar we don’t likevery much
RSpec done
Problem of Fixtures
Hard to readHard to writeHard to maintain
What’s the password?
What’s the password?Add new records?
Fixtures separate thedata and the tests
Bullshit!
What’s the advantageof fixtures?
It’s really fast!!
Some practices forFactory Girl
Random data is aadvantage of factoryto fixtures
Update: If you wanna useLoremIpsum class stillneed the gems likeforgery or lorem-ipsum.
How we run tests?
You might see this
But......I really don’t use it
Tell you a secret
I run my tests manually
Why?
probably, I type:wso frequentlyand quickly. LOL
Your APM should be high
Slayers BoxerYour APM should be high
Manually run‘bundle exec rspec spec’ ?
No. It depends.
bundle exec rspec specruby -S rspec spec
Bundler still needtime to load
When I can not use‘bundle exec’ ?
no spec_helper
Two ways to run tests?
ruby -S rspec spec ?
bundle exec rspec spec ?ruby -S rspec spec ?
by Gray Bernhardt
About integration test
RSpec +Capybara(webkit)
Poltergeist looks nicewill give it a try
I don’t love it so farAlso don’t hate itStill keep looking
Stub as little as possibleonly do forCurrent timeHTTP visiting...
VCR
Use different fixturedata in integration andunit tests
Integration tests arenot for drivingdevelopment
No mock or stubmeans slowYou can use a CIserver run it for you
if project.open_source?
A hosted continuous integration service for the open source community.
else
integrity• light weight• It built by ruby (Means you can hack!!!)• Works pretty well with git• Hook and API is weak
Hudson and Jenkins• They built by JAVA• Heavy weight and powerful• a lot of plugins(git, github, emails, hipchat...)• Have nice API
We really did some interestingthings with Hudson by HUBOT
http://terrytai.com/
JS tests
jasminerice gem for work with Rails asset pipeline
jasmine-sinon
By Ian: https://gist.github.com/4059889
Look at me, Terry. It’s not a JS conf, ok?
I’d better stop here
Oh, BTW
DHH is the heroin my heart
Thank you!