wtf is tdd
TRANSCRIPT
![Page 1: WTF is TDD](https://reader033.vdocuments.site/reader033/viewer/2022052321/554a1b79b4c90507558b55fc/html5/thumbnails/1.jpg)
WTF is TDDA journey to writing awesome code, one test at a time
![Page 2: WTF is TDD](https://reader033.vdocuments.site/reader033/viewer/2022052321/554a1b79b4c90507558b55fc/html5/thumbnails/2.jpg)
WTF we'll be covering● What is testing and why you are hurting the
world by not doing it● What is TDD, why do it, and why it's better
than writing tests AFTER you've written your code
● See code that was developed using TDD● Extending this code
![Page 3: WTF is TDD](https://reader033.vdocuments.site/reader033/viewer/2022052321/554a1b79b4c90507558b55fc/html5/thumbnails/3.jpg)
Who TF is this guy?● Steven Nunez (@_StevenNunez)
○ Junior Developer at Cyrus Innovation■ AWESOME PLACE!
● Agile/TDD All day, E'ryday○ Organizer of Unearth Ruby
■ http://www.meetup.com/unearthruby/○ Co-Organizer of NYC Rubyist Roundtable
■ http://www.meetup.com/nycruby/
![Page 4: WTF is TDD](https://reader033.vdocuments.site/reader033/viewer/2022052321/554a1b79b4c90507558b55fc/html5/thumbnails/4.jpg)
Stuff you need to F'ing knowHow to read this:class Order attr_reader :items
def initialize @items = Hash.new(0) end
def add(item) items[item] += 1 end end
![Page 5: WTF is TDD](https://reader033.vdocuments.site/reader033/viewer/2022052321/554a1b79b4c90507558b55fc/html5/thumbnails/5.jpg)
The Act of isolating parts of your code with a known state to ensure it works as expected.
Setup follows AAA principle:
ArrangeAct Assert
What Is Testing
![Page 6: WTF is TDD](https://reader033.vdocuments.site/reader033/viewer/2022052321/554a1b79b4c90507558b55fc/html5/thumbnails/6.jpg)
Types of testing● End to end tests/ Acceptance tests
○ Here there be Cucumbers. Capybara, Webrat○ Used to ensure system works as a whole
● Unit Tests○ Rspec, Test::Unit, Minitest○ View tests○ Controller tests○ Model tests
![Page 7: WTF is TDD](https://reader033.vdocuments.site/reader033/viewer/2022052321/554a1b79b4c90507558b55fc/html5/thumbnails/7.jpg)
● Lets you know when things broke○ You'd be surprised how code works
● Allows for courageous refactoring● Gives documentation on how your code is
SUPPOSED to work● It is your duty to deliver working code.
Why Test
![Page 8: WTF is TDD](https://reader033.vdocuments.site/reader033/viewer/2022052321/554a1b79b4c90507558b55fc/html5/thumbnails/8.jpg)
Testing basicsWe'll be using Rspec...http://rspec.info/https://github.com/rspec/rspec-expectations#built-in-matchers
Codey Code! ----> http://bit.ly/PUwQLf
![Page 9: WTF is TDD](https://reader033.vdocuments.site/reader033/viewer/2022052321/554a1b79b4c90507558b55fc/html5/thumbnails/9.jpg)
What is Test Driven Development?
![Page 10: WTF is TDD](https://reader033.vdocuments.site/reader033/viewer/2022052321/554a1b79b4c90507558b55fc/html5/thumbnails/10.jpg)
Why do TDD?● Forces you to think small
○ You have a clear objective● Less thoughts to juggle
○ All you know is how you want it to work● Leads to modular code
○ Each part of your code does one job● Write less code● Increase documentation ● It makes you happy!
○ Red, Green, REFACTOR!http://edu.mkrecny.com/thoughts/be-nice-to-programmers
![Page 11: WTF is TDD](https://reader033.vdocuments.site/reader033/viewer/2022052321/554a1b79b4c90507558b55fc/html5/thumbnails/11.jpg)
How to TDDRed Green Refactor 1. Write a test.2. Watch it fail.3. Write code to pass your test.4. Look for ways to make your code more
expressive5. GOTO 1
![Page 12: WTF is TDD](https://reader033.vdocuments.site/reader033/viewer/2022052321/554a1b79b4c90507558b55fc/html5/thumbnails/12.jpg)
Our projectOur client is developing a social network based for his Restaurant customers. He'd want to eventually have people with similar food interests meet up and discuss how his food changed their lives.
● A few features he wants are: ○ The ability to have users discover new foods based on ingredients they love (Bacon!)○ The ability to find users with similar food interests. The system will automatically share their phone
numbers with each other. (He thinks they'll be ok with this)What do you need first?I need a way to capture customer orders based on their menu.
Things we built A Menu with Menu Items in it. The Items need to have a name, price, calorie count, and ingredientsOrders consist of a menu item, and a quantity.Orders can calculate their total
![Page 13: WTF is TDD](https://reader033.vdocuments.site/reader033/viewer/2022052321/554a1b79b4c90507558b55fc/html5/thumbnails/13.jpg)
Your task!Pair up and work on getting the recommendation engine up.
Noobs, pair up with Wizards.
TDD ONLY!
https://github.com/StevenNunez/FinerDiner
![Page 14: WTF is TDD](https://reader033.vdocuments.site/reader033/viewer/2022052321/554a1b79b4c90507558b55fc/html5/thumbnails/14.jpg)
Questions!
![Page 15: WTF is TDD](https://reader033.vdocuments.site/reader033/viewer/2022052321/554a1b79b4c90507558b55fc/html5/thumbnails/15.jpg)
TaskMenu#recommendations(:bacon)# => [:bacon_cheeseburger, :blt, :bacone ]
Socializer#socialize!# customer_1.hook_up(customer_2)
![Page 16: WTF is TDD](https://reader033.vdocuments.site/reader033/viewer/2022052321/554a1b79b4c90507558b55fc/html5/thumbnails/16.jpg)
Resourceshttps://www.relishapp.com/rspechttp://pragprog.com/book/achbd/the-rspec-bookPractical Object Oriented Design by Sandy Mentzhttp://www.poodr.info/
![Page 17: WTF is TDD](https://reader033.vdocuments.site/reader033/viewer/2022052321/554a1b79b4c90507558b55fc/html5/thumbnails/17.jpg)
THANKS!