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

Its Never an Engineering Error...

Its Never an Engineering Error...

Ryan Castillo

March 12, 2013
Tweet

More Decks by Ryan Castillo

Other Decks in Programming

Transcript

  1. describe Sender do it "is in a content mood when

    listened to" do significant_other = Sender.new("I had a good day") me = double(Recipient) me.stub(:listened_to_day?) { true } significant_other.describe_day_to(me) significant_other.mood.should >= "content" end end
  2. class Sender def initialize(message) @message = message end def mood

    if @feel_acknowledged "content" end end def describe_day_to(another_person) if another_person.listened_to_day? @feel_acknowledged = true end end end class Recipient end
  3. describe Sender do it "is in a content mood when

    understood" do significant_other = Sender.new "I had a good day" me = Recipient.new significant_other.describe_day_to(me) significant_other.mood.should >= "content" end end
  4. class Sender # folded non-refactored code def describe_day_to(another_person) interpretation =

    another_person.interpret(@said) if satisfied_with_interpretation?(interpretation) @feel_acknowledged = true end end def satisfied_with_interpretation?(interpretation) shared_words = interpretation.split(' ') & @said.split(' ') true if shared_words.size >= 2 end end
  5. class Recipient def interpret(sentence) if sentence == "I had a

    good day" "I'm glad you had a good day" end end end
  6. describe Sender do # folded non-refactored code it "is in

    a content mood when all frustrations are understood" do complaints = ["Heroku was down", "There was ruby drama on twitter", "My presentation isn't done yet"] me = Sender.new complaints significant_other = Recipient.new me.describe_day_to(significant_other) me.mood.should >= "content" end end
  7. class Sender # folded non-refactored code def describe_day_to(another_person) @messages.each do

    |message| interpretation = another_person.interpret(message) if satisfied_with_interpretation?(interpretation, message) @feel_acknowledged = true else @feel_acknowledged = false end end end def satisfied_with_interpretation?(interpretation, message) shared_words = interpretation.split(' ') & message.split(' ') true if shared_words.size >= 1 end end
  8. class Recipient def interpret(sentence) if sentence == "I had a

    good day" "I'm glad you had a good day" elsif sentence == "Heroku was down" "What is Heroku?" elsif sentence == "There was ruby drama on twitter" "There is drama with ruby? Isn't it a programming language?" elsif sentence == "My presentation isn't done yet" "I'm sorry your presentation is taking so long" end end end
  9. I'm trying to learn some bioinformatics using Ruby with a

    book written for Perl. Could you please help me get this working?
  10. Who do I shout at for this crap pile of

    code I have to deal with?