Upgrade to Pro — share decks privately, control downloads, hide ads and more …

In the Driver's Seat: How MSPec and BDD Will Make You a Better Programmer

Joe Leo
June 26, 2013

In the Driver's Seat: How MSPec and BDD Will Make You a Better Programmer

Joe Leo

June 26, 2013
Tweet

Other Decks in Technology

Transcript

  1. How MSpec and BDD Will Make You a Better Programmer

    Joe Leo IN THE DRIVER’S SEAT: @jleo3
  2. Surprise! We’re Hiring! • Great money, benefits! • Genuine agile

    work environment! • Personal Chauffers! • Swimming pools filled with champagne! • Work in .NET, Java, Scala, and more! • Work with ME!
  3. Outline • Who's this guy and why should we listen

    to someone with crazy hair and a huge beard? • What can writing Ruby teach me about .NET? • An Intro to MSpec: "Poking the Tiger" • Get Drunk with Einstein
  4. Where Does This Guy Come From? • From Ruby Land.

    • In RoR, where the tests roam free
  5. S.O.L.I.D. Design Principles • 5 Basic principles of object oriented

    design • Often attributed to Uncle Bob Martin • Actually a mnemonic created by Michael Feathers • Michael Feathers is awesome so stop giving Martin all the credit!
  6. S.O.L.I.D. continued • Single Responsibility • Open-closed principle • Liskov

    Substitution • Interface Segregation • Dependency Inversion
  7. Damn Good Testing LOC, Totals grouped by language: • ruby:

    46575 (98.82%) • xml: 354 (0.75%) • sh: 200 (0.42%) Test Coverage: 98.37%
  8. Commence Hand-Wringing • “This is just a proof of concept.”

    • “We have to get this done as quickly as possible.” • “Our team doesn’t do testing that way.” • “Stop talking to me! We’re losing $75,000 a day and I need to find a new job!”
  9. Axiom: The best way to produce robust and beautiful code

    is to start with elegantly crafted tests.
  10. This is MSpec “Machine.Specifications is a Context/Specification framework geared towards

    removing language noise and simplifying tests.” • Inspired by RSpec • Emphasis on grammar – Subject, Establish, Because, It • Plug-N-Play with mocking frameworks
  11. Wordy Gurdy • Given / When / Then • Describe

    / It / Should • Test / Setup / Assert • Establish / Because / It
  12. Make Because/It One Line Apiece “MSpec is designed to reduce

    noise in tests. You should generally only have one line in your It and Because statements... Context/Specification testing, while a rethinking of "classic" TDD, still abides by the rules of Arrange-Act-Assert. As such, it is preferable to keep the latter two as succinct as possible.”
  13. Single Responsibility Principle "There should never be more than one

    reason for a class to change." -- Uncle Bob Martin
  14. Axioms • Specs should involve the least amount of setup

    possible for executing expectations. • Specs that exercise the same responsibility should have similar setups.
  15. • FizzBuzz: Simple Programming Problem • FizzBuzz: Not as easy

    as it looks • FizzBuzz: Gauntlet of Death
  16. FizzBuzz with Einstein It’s the summer of 1923. You and

    a few friends are on holiday in Goeteborg, Sweden. After one round of starköl in the Nobel Bar you start to feel funny. So you make fun of people around you – loudly. As you spot someone who has that distinct Einstein-haircut you tell him that "only two things are infinite, the universe and your stupidity, and I’m not sure about the former". As it turns out this man is indeed Einstein celebrating after his nobel price acceptance speech – and now he is mad at you. To settle this issue like civilized gentlemen he proposes a little drinking game called "fizz-buzz". In order to leave the table without a serious alcohol poisoning but some of your pride left you decide to do what every person would do: Cheat!
  17. The Rules • One person calls out a number •

    The other person determines the next 3 numbers based on the following: o If the number is divisible by three, say "Fizz" o If the number is divisible by five, say "Buzz" o If the number is divisible by both, say "FizzBuzz" o If none of the above are met, repeat the number. If you’re wrong, you drink. If you’re right the other person drinks.
  18. In broader terms At any given time there will be

    3 rules x, y, and z such that for a given input i o If x(i) and y(i) then z(i) o If x(i) and !y(i) then x(i) o If !x(i) and y(i) then y(i) o If !x(i) and !y(i) then i
  19. Axioms • Fewer requirements lead to smaller objects. • Smaller

    objects have a better chance of being SOLID.
  20. Axioms • Specs should involve the least amount of setup

    possible for executing expectations. • Specs that exercise the same responsibility should have similar setups.
  21. Wrapping Up • Learning Ruby is good for you. •

    Poking Tigers is dangerous but safer if you use interfaces. • Don’t make fun of Einstein until you’ve had some experience with BDD • Even guys with crazy beards and giant curly hair are occasionally useful.
  22. Finally… • I want your feedback! • http://bit.ly/134aAuQ • Your

    feedback == $$ for the American Red Cross Disaster Relief fund.