View stunning SlideShares in full-screen with the new iOS app!Introducing SlideShare for AndroidExplore all your favorite topics in the SlideShare appGet the SlideShare app to Save for Later — even offline
View stunning SlideShares in full-screen with the new Android app!View stunning SlideShares in full-screen with the new iOS app!
Rails Automatic Test Driven Development• About the author• Test Driven Development• Testing for Rails• RSpec & Capybara• Spork & Guard• Test inside Sublime Text• Show time• References• Q&A
About the author• Tyler Long (龙泰勒)• 6 years of software development experience• 2 years as Senior Software Development Manager• Home page: http://tylerlong.me• Weibo.com: @龙泰勒• Github: https://github.com/tylerlong• Bitbucket: https://bitbucket.org/tylerlong
Test Driven Development - 1• Three laws of TDD – First Law: You may not write production code until you have written a failing unit test. – Second Law: You may not write more of a unit test than is sufficient to fail, and not compiling is failing. – Third Law: You may not write more production code than is sufficient to pass the current failing test.
Test Driven Development - 2• The TDD Cycle – We first write a failing test, represented in many testing tools by the color red. – We then implement code to get the test to pass, represented by the color green. – Finally, if necessary, we refactor the code, changing its form without changing its function. – This cycle is known as “Red, Green, Refactor”.
Testing for Rails• Test::Unit – lightweight and straightforward• RSpec (my choice) – has a lot of stuff which makes testing easier• Cucumber – good for making sure all these sort of high-level features and functionalities are covered
RSpec & Capybara• RSpec – RSpec is designed to make Test-Driven Development a productive and enjoyable experience – http://rspec.info/• Capybara – Capybara makes it easy to simulate how a user interacts with your application. – http://jnicklas.github.com/capybara/
Spork & Guard• Spork – A DRb server for testing frameworks (RSpec / Cucumber currently) that forks before each run to ensure a clean testing state. – https://github.com/sporkrb/spork• Guard – Guard is a command line tool to easily handle events on file system modifications – https://github.com/guard/guard
Test inside Sublime Text• Sublime Text – Sublime Text is a sophisticated text editor for code, html and prose. – I switched from Vim to Sublime Text• Run tests directly inside the editor, doesn’t it sound cool? – https://github.com/maltize/sublime-text-2-ruby- tests
References• Ruby on Rails Tutorial: http://ruby.railstutorial.org/chapters/static- pages?version=3.2• The true meaning of TDD: http://tylerlong.me/1331043344/• Rails TDD (In Chinese): http://tylerlong.me/1332078416/