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

Discovering Better OO Design with Test

Roy Young
November 23, 2013

Discovering Better OO Design with Test

Rubyconf China 2013

Roy Young

November 23, 2013
Tweet

Other Decks in Programming

Transcript

  1. Why hate to write test? * Hard to think about

    how to start. * Protect our code. Saturday, November 23, 13
  2. Why hate to write test? * Hard to think about

    how to start. * It is painful, can’t keep on going. * Protect our code. Saturday, November 23, 13
  3. Why hate to write test? * Hard to think about

    how to start. * It is painful, can’t keep on going. * Protect our code. Write test after implementation! Saturday, November 23, 13
  4. Why hate to write test? * Hard to think about

    how to start. * It is painful, can’t keep on going. * Protect our code. Write test after implementation! It is not TDD. Saturday, November 23, 13
  5. Something behind that * Hard to think about how to

    write it. * It is painful, can’t keep on going. Saturday, November 23, 13
  6. Something behind that * Hard to think about how to

    write it. * It is painful, can’t keep on going. * Write it Step by Step, test reflect your design structure. Saturday, November 23, 13
  7. Something behind that * Hard to think about how to

    write it. * It is painful, can’t keep on going. * It is a signal about your bad design. * Write it Step by Step, test reflect your design structure. Saturday, November 23, 13
  8. Why need OO design? * Code is unclearly. * Hard

    to understand. Saturday, November 23, 13
  9. Why need OO design? * Code is unclearly. * Hard

    to understand. * It is unmaintainable. Saturday, November 23, 13
  10. Refactor the bad structure as earlier as possible. Test reflects

    the design structure. Saturday, November 23, 13
  11. Refactor the bad structure as earlier as possible. Test reflects

    the design structure. Discovering better OO design with test Saturday, November 23, 13
  12. Pragmatic.ly Working Flow SendCloud Client 1.Tell SendCloud to send email.

    2.Send out the email to clients. Saturday, November 23, 13
  13. Pragmatic.ly Working Flow SendCloud Client 1.Tell SendCloud to send email.

    2.Send out the email to clients. 3.Client reply the email. Saturday, November 23, 13
  14. Pragmatic.ly Working Flow SendCloud Client 1.Tell SendCloud to send email.

    2.Send out the email to clients. 3.Client reply the email. 4.SendCloud webhook send a post request to our callback url. Saturday, November 23, 13
  15. Pragmatic.ly Working Flow SendCloud Client 1.Tell SendCloud to send email.

    2.Send out the email to clients. 3.Client reply the email. 4.SendCloud webhook send a post request to our callback url. 5.Create a comment. Saturday, November 23, 13
  16. Pragmatic.ly Working Flow SendCloud Client 1.Tell SendCloud to send email.

    2.Send out the email to clients. 3.Client reply the email. 4.SendCloud webhook send a post request to our callback url. 5.Create a comment. Saturday, November 23, 13
  17. What we need to do? Pragmatic.ly SendCloud 1. Verify the

    post request. Saturday, November 23, 13
  18. What we need to do? Pragmatic.ly SendCloud 1. Verify the

    post request. Saturday, November 23, 13
  19. What we need to do? Pragmatic.ly SendCloud Reply-To: [email protected] 1.

    Verify the post request. Saturday, November 23, 13
  20. What we need to do? Pragmatic.ly SendCloud Reply-To: [email protected] 1.

    Verify the post request. 2. Validate the reply email information. Saturday, November 23, 13
  21. What we need to do? Pragmatic.ly SendCloud Reply-To: [email protected] 1.

    Verify the post request. 2. Validate the reply email information. 3.Create a comment. Saturday, November 23, 13
  22. Where to begin with class EmailRepliesController < ApplicationController def create

    end end I need a callback url Saturday, November 23, 13
  23. Where to begin with class EmailRepliesController < ApplicationController def create

    end end I need a callback url Test First Saturday, November 23, 13
  24. Where to begin with class EmailRepliesController < ApplicationController def create

    end end I need a callback url describe EmailRepiesController do describe "POST create" do end end Test First Saturday, November 23, 13
  25. Verify Post Request Source describe EmailRepiesController do describe "POST create"

    do context "when the post request is a valid request" do end end end Saturday, November 23, 13
  26. context "when the post request is not a valid request"

    do Verify Post Request Source describe EmailRepiesController do describe "POST create" do context "when the post request is a valid request" do end end end end Saturday, November 23, 13
  27. context "when the post request is not a valid request"

    do Verify Post Request Source describe EmailRepiesController do describe "POST create" do context "when the post request is a valid request" do it "returns status 200" end end end end Saturday, November 23, 13
  28. context "when the post request is not a valid request"

    do Verify Post Request Source describe EmailRepiesController do describe "POST create" do context "when the post request is a valid request" do it "returns status 200" end it "returns status 422" end end end Saturday, November 23, 13
  29. What we need to do? Pragmatic.ly SendCloud Reply-To: [email protected] 1.

    Verify the post request. 2. The reply email information. 3.Create a comment. Saturday, November 23, 13
  30. What we need to do? Pragmatic.ly SendCloud Reply-To: [email protected] 1.

    Verify the post request. 2. The reply email information. 3.Create a comment. Saturday, November 23, 13
  31. Validation & Creation describe "POST create" do context "when the

    post request is a valid request" do it "returns status 200" end end Saturday, November 23, 13
  32. Validation & Creation describe "POST create" do context "when the

    post request is a valid request" do it "returns status 200" end end Saturday, November 23, 13
  33. Validation & Creation describe "POST create" do context "when the

    post request is a valid request" do it "returns status 200" end end context "when the project uid is valid" do end Saturday, November 23, 13
  34. context "when the project uid is invalid" do end Validation

    & Creation describe "POST create" do context "when the post request is a valid request" do it "returns status 200" end end context "when the project uid is valid" do end Saturday, November 23, 13
  35. context "when the project uid is invalid" do end Validation

    & Creation describe "POST create" do context "when the post request is a valid request" do it "returns status 200" end end context "when the project uid is valid" do end it "doesn't create the comment" Saturday, November 23, 13
  36. Validation & Creation context "when the project uid is valid"

    do end context "when the user email is valid" do end Saturday, November 23, 13
  37. context "when the user uid is invalid" do it "doesn't

    create the comment" end Validation & Creation context "when the project uid is valid" do end context "when the user email is valid" do end Saturday, November 23, 13
  38. context "when the user uid is invalid" do it "doesn't

    create the comment" end Validation & Creation context "when the project uid is valid" do end context "when the user email is valid" do end context "when the user has the right to access this project" do end Saturday, November 23, 13
  39. context "when the user uid is invalid" do it "doesn't

    create the comment" end Validation & Creation context "when the project uid is valid" do end context "when the user email is valid" do end context "when the user has the right to access this project" do context "when the user has no right to access this project" do it "doesn't create the comment" end end Saturday, November 23, 13
  40. context "when the user uid is invalid" do it "doesn't

    create the comment" end Validation & Creation context "when the project uid is valid" do end context "when the user email is valid" do end context "when the user has the right to access this project" do context "when the user has no right to access this project" do it "doesn't create the comment" end end # Next Step Saturday, November 23, 13
  41. context "when the user has the right to access this

    project" do Validation & Creation end Saturday, November 23, 13
  42. context "when the ticket uid is valid" do context "when

    the user has the right to access this project" do Validation & Creation end end Saturday, November 23, 13
  43. context "when the ticket uid is valid" do context "when

    the ticket uid is invalid" do context "when the user has the right to access this project" do Validation & Creation end end end Saturday, November 23, 13
  44. context "when the ticket uid is valid" do context "when

    the ticket uid is invalid" do it "creates the comment" context "when the user has the right to access this project" do Validation & Creation end end end Saturday, November 23, 13
  45. context "when the ticket uid is valid" do context "when

    the ticket uid is invalid" do it "doesn't create the comment" it "creates the comment" context "when the user has the right to access this project" do Validation & Creation end end end Saturday, November 23, 13
  46. What do we get now? context "when the project uid

    is valid" do context "when the user uid is valid" do context "when the user has the right to access this project" do context "when the ticket uid is valid" do it "creates the comment for iteration" end context "when the ticket uid is invalid" do it "doesn't create the comment" end end context "when the user has no right to access this project" do it "doesn't create the comment" end end context "when the user uid is invalid" do it "doesn't create the comment" end end context "when the project uid is invalid" do it "doesn't create the comment" end Saturday, November 23, 13
  47. What do we get now? context "when the project uid

    is valid" do context "when the user uid is valid" do context "when the user has the right to access this project" do context "when the ticket uid is valid" do it "creates the comment for iteration" end context "when the ticket uid is invalid" do it "doesn't create the comment" end end context "when the user has no right to access this project" do it "doesn't create the comment" end end context "when the user uid is invalid" do it "doesn't create the comment" end end context "when the project uid is invalid" do it "doesn't create the comment" end Controller Saturday, November 23, 13
  48. What do we get now? context "when the project uid

    is valid" do context "when the user uid is valid" do context "when the user has the right to access this project" do context "when the ticket uid is valid" do it "creates the comment for iteration" end context "when the ticket uid is invalid" do it "doesn't create the comment" end end context "when the user has no right to access this project" do it "doesn't create the comment" end end context "when the user uid is invalid" do it "doesn't create the comment" end end context "when the project uid is invalid" do it "doesn't create the comment" end Controller SendCloud Saturday, November 23, 13
  49. What do we get now? context "when the project uid

    is valid" do context "when the user uid is valid" do context "when the user has the right to access this project" do context "when the ticket uid is valid" do it "creates the comment for iteration" end context "when the ticket uid is invalid" do it "doesn't create the comment" end end context "when the user has no right to access this project" do it "doesn't create the comment" end end context "when the user uid is invalid" do it "doesn't create the comment" end end context "when the project uid is invalid" do it "doesn't create the comment" end Project Controller SendCloud Saturday, November 23, 13
  50. What do we get now? context "when the project uid

    is valid" do context "when the user uid is valid" do context "when the user has the right to access this project" do context "when the ticket uid is valid" do it "creates the comment for iteration" end context "when the ticket uid is invalid" do it "doesn't create the comment" end end context "when the user has no right to access this project" do it "doesn't create the comment" end end context "when the user uid is invalid" do it "doesn't create the comment" end end context "when the project uid is invalid" do it "doesn't create the comment" end Project User Controller SendCloud Saturday, November 23, 13
  51. What do we get now? context "when the project uid

    is valid" do context "when the user uid is valid" do context "when the user has the right to access this project" do context "when the ticket uid is valid" do it "creates the comment for iteration" end context "when the ticket uid is invalid" do it "doesn't create the comment" end end context "when the user has no right to access this project" do it "doesn't create the comment" end end context "when the user uid is invalid" do it "doesn't create the comment" end end context "when the project uid is invalid" do it "doesn't create the comment" end Project User Ticket Controller SendCloud Saturday, November 23, 13
  52. What do we get now? context "when the project uid

    is valid" do context "when the user uid is valid" do context "when the user has the right to access this project" do context "when the ticket uid is valid" do it "creates the comment for iteration" end context "when the ticket uid is invalid" do it "doesn't create the comment" end end context "when the user has no right to access this project" do it "doesn't create the comment" end end context "when the user uid is invalid" do it "doesn't create the comment" end end context "when the project uid is invalid" do it "doesn't create the comment" end Project User Ticket Comment Controller SendCloud Saturday, November 23, 13
  53. What do we get now? context "when the project uid

    is valid" do context "when the user uid is valid" do context "when the user has the right to access this project" do context "when the ticket uid is valid" do it "creates the comment for iteration" end context "when the ticket uid is invalid" do it "doesn't create the comment" end end context "when the user has no right to access this project" do it "doesn't create the comment" end end context "when the user uid is invalid" do it "doesn't create the comment" end end context "when the project uid is invalid" do it "doesn't create the comment" end Project User Ticket Comment Controller SendCloud Saturday, November 23, 13
  54. What do we get now? context "when the project uid

    is valid" do context "when the user uid is valid" do context "when the user has the right to access this project" do context "when the ticket uid is valid" do it "creates the comment for iteration" end context "when the ticket uid is invalid" do it "doesn't create the comment" end end context "when the user has no right to access this project" do it "doesn't create the comment" end end context "when the user uid is invalid" do it "doesn't create the comment" end end context "when the project uid is invalid" do it "doesn't create the comment" end Project User Ticket Comment Controller SendCloud Saturday, November 23, 13
  55. def create No Test! if post_request_valid project = Project.find(...) if

    project.valid user = User.find(...) Saturday, November 23, 13
  56. def create No Test! if post_request_valid project = Project.find(...) if

    project.valid user = User.find(...) if user.valid Saturday, November 23, 13
  57. def create No Test! if post_request_valid project = Project.find(...) if

    project.valid user = User.find(...) if user.valid if user.have_access_right Saturday, November 23, 13
  58. def create No Test! if post_request_valid project = Project.find(...) if

    project.valid user = User.find(...) if user.valid if user.have_access_right ticket = Ticket.find(...) Saturday, November 23, 13
  59. def create No Test! if post_request_valid project = Project.find(...) if

    project.valid user = User.find(...) if user.valid if user.have_access_right ticket = Ticket.find(...) if ticket.valid Saturday, November 23, 13
  60. def create No Test! if post_request_valid project = Project.find(...) if

    project.valid user = User.find(...) if user.valid if user.have_access_right ticket = Ticket.find(...) if ticket.valid Comment.create(...) Saturday, November 23, 13
  61. def create No Test! if post_request_valid project = Project.find(...) if

    project.valid user = User.find(...) if user.valid if user.have_access_right ticket = Ticket.find(...) if ticket.valid Comment.create(...) end else ... end else ... end else .... Saturday, November 23, 13
  62. def create No Test! if post_request_valid project = Project.find(...) if

    project.valid user = User.find(...) if user.valid if user.have_access_right ticket = Ticket.find(...) if ticket.valid Comment.create(...) end else ... end else ... end else .... Saturday, November 23, 13
  63. def create No Test! if post_request_valid project = Project.find(...) if

    project.valid user = User.find(...) if user.valid if user.have_access_right ticket = Ticket.find(...) if ticket.valid Comment.create(...) end else ... end else ... end else .... Refactor it? Saturday, November 23, 13
  64. def create No Test! if post_request_valid project = Project.find(...) if

    project.valid user = User.find(...) if user.valid if user.have_access_right ticket = Ticket.find(...) if ticket.valid Comment.create(...) end else ... end else ... end else .... Refactor it? It is too late! Saturday, November 23, 13
  65. def create No Test! if post_request_valid project = Project.find(...) if

    project.valid user = User.find(...) if user.valid if user.have_access_right ticket = Ticket.find(...) if ticket.valid Comment.create(...) end else ... end else ... end else .... Refactor it? It is too late! Technical Debt Saturday, November 23, 13
  66. Let’s go back context "when the project uid is valid"

    do context "when the user uid is valid" do context "when the user has the right to access this project" do context "when the ticket uid is valid" do it "creates the comment for iteration" end context "when the ticket uid is invalid" do it "doesn't create the comment" end end context "when the user has no right to access this project" do it "doesn't create the comment" end end context "when the user uid is invalid" do it "doesn't create the comment" end end context "when the project uid is invalid" do it "doesn't create the comment" end Saturday, November 23, 13
  67. Test reflect the design Controller context "when the post request

    is a valid request" do describe "POST create" do SendCloud Saturday, November 23, 13
  68. Test reflect the design context "when the project uid is

    valid" do Controller Project context "when the post request is a valid request" do describe "POST create" do SendCloud Saturday, November 23, 13
  69. Test reflect the design context "when the project uid is

    valid" do Controller Project User context "when the user uid is valid" do context "when the post request is a valid request" do describe "POST create" do SendCloud Saturday, November 23, 13
  70. Test reflect the design context "when the project uid is

    valid" do Controller Project User context "when the user uid is valid" do context "when the user has the right to access this project" do context "when the post request is a valid request" do describe "POST create" do SendCloud Saturday, November 23, 13
  71. Test reflect the design context "when the project uid is

    valid" do Controller Project User Ticket context "when the user uid is valid" do context "when the user has the right to access this project" do context "when the ticket uid is valid" do context "when the post request is a valid request" do describe "POST create" do SendCloud Saturday, November 23, 13
  72. Test reflect the design context "when the project uid is

    valid" do Controller Project User Ticket Comment context "when the user uid is valid" do context "when the user has the right to access this project" do context "when the ticket uid is valid" do it "creates the comment for iteration" context "when the post request is a valid request" do describe "POST create" do SendCloud Saturday, November 23, 13
  73. 1. I didn’t write any codes 2. What did I

    find with test Saturday, November 23, 13
  74. Test reflect the design Structural Coupling! Controller Project User Ticket

    Comment SendCloud Doing too many things! Saturday, November 23, 13
  75. Test reflect the design Structural Coupling! Controller Project User Ticket

    Comment SendCloud Doing too many things! Knowing too much details! Saturday, November 23, 13
  76. context "when the post request is a valid request" do

    context "when the project uid is valid" do context "when the user uid is valid" do context "when the user has the right to access this project" do context "when the ticket uid is valid" do it "creates the comment for iteration" SendCloud Re-Design From Test Controller Project User Ticket Comment Saturday, November 23, 13
  77. context "when the post request is a valid request" do

    context "when the project uid is valid" do context "when the user uid is valid" do context "when the user has the right to access this project" do context "when the ticket uid is valid" do it "creates the comment for iteration" SendCloud Re-Design From Test Controller Project User Ticket Comment Saturday, November 23, 13
  78. context "when the post request is a valid request" do

    context "when the project uid is valid" do context "when the user uid is valid" do context "when the user has the right to access this project" do context "when the ticket uid is valid" do it "creates the comment for iteration" SendCloud Re-Design From Test Controller Project User Ticket Comment Saturday, November 23, 13
  79. Re-Design SendCloud Controller context "when the post request is a

    valid request" do Saturday, November 23, 13
  80. Re-Design SendCloud Controller context "when the post request is a

    valid request" do it "tells email handler to handle the request" do end Saturday, November 23, 13
  81. Re-Design SendCloud Controller context "when the post request is a

    valid request" do it "tells email handler to handle the request" do end Saturday, November 23, 13
  82. Re-Design SendCloud Controller context "when the post request is a

    valid request" do it "tells email handler to handle the request" do end email_handler = EmailHandler.any_instance Saturday, November 23, 13
  83. Re-Design SendCloud Controller context "when the post request is a

    valid request" do it "tells email handler to handle the request" do end email_handler = EmailHandler.any_instance Saturday, November 23, 13
  84. Re-Design SendCloud Controller context "when the post request is a

    valid request" do it "tells email handler to handle the request" do end email_handler = EmailHandler.any_instance email_handler.should_receive(:handle) Saturday, November 23, 13
  85. Re-Design SendCloud Controller context "when the post request is a

    valid request" do it "tells email handler to handle the request" do end email_handler = EmailHandler.any_instance post :create, timestamp: timestamps, token: token, signature: signature email_handler.should_receive(:handle) Saturday, November 23, 13
  86. Re-Design SendCloud Controller EmailHandler context "when the post request is

    a valid request" do it "tells email handler to handle the request" do end email_handler = EmailHandler.any_instance post :create, timestamp: timestamps, token: token, signature: signature email_handler.should_receive(:handle) Saturday, November 23, 13
  87. Re-Design SendCloud Controller EmailHandler Mock context "when the post request

    is a valid request" do it "tells email handler to handle the request" do end email_handler = EmailHandler.any_instance post :create, timestamp: timestamps, token: token, signature: signature email_handler.should_receive(:handle) Saturday, November 23, 13
  88. Re-Design Controller class EmailRepliesController < ApplicationController def create if post_request_authenticated

    EmailHandler.new(params).handle head(200) else head(422) end end def post_request_authenticated ... end end Saturday, November 23, 13
  89. Re-Design Controller class EmailRepliesController < ApplicationController def create if post_request_authenticated

    EmailHandler.new(params).handle head(200) else head(422) end end def post_request_authenticated ... end end email_handler = EmailHandler.any_instance email_handler.should_receive(:handle) Test Saturday, November 23, 13
  90. Re-Design Controller class EmailRepliesController < ApplicationController def create if post_request_authenticated

    EmailHandler.new(params).handle head(200) else head(422) end end def post_request_authenticated ... end end email_handler = EmailHandler.any_instance email_handler.should_receive(:handle) Test Saturday, November 23, 13
  91. New Class EmailHandler class EmailHandler def initialize(params) end def handle

    end end EmailHandler.new(params).handle Saturday, November 23, 13
  92. New Class EmailHandler class EmailHandler def initialize(params) end def handle

    end end describe EmailHandler do describe "#initialize" do end describe "#handle" do end end EmailHandler.new(params).handle Saturday, November 23, 13
  93. New Class EmailHandler class EmailHandler def initialize(params) end def handle

    end end describe EmailHandler do describe "#initialize" do end describe "#handle" do end end describe "#handle" do end EmailHandler.new(params).handle Saturday, November 23, 13
  94. New Class EmailHandler class EmailHandler def initialize(params) end def handle

    end end describe EmailHandler do describe "#initialize" do end describe "#handle" do end end context "when the project uid is valid" do context "when the user email is valid" do context "when the user has the right to access this project" do context "when the ticket uid is valid" do .... describe "#handle" do end EmailHandler.new(params).handle Saturday, November 23, 13
  95. EmailHandler#handle context "when the project uid is valid" do context

    "when the user email is valid" do context "when the user has the right to access this project" do context "when the ticket uid is valid" do .... describe "#handle" do end Saturday, November 23, 13
  96. EmailHandler#handle context "when the project uid is valid" do context

    "when the user email is valid" do context "when the user has the right to access this project" do context "when the ticket uid is valid" do .... describe "#handle" do end Saturday, November 23, 13
  97. EmailHandler#handle context "when the project uid is valid" do context

    "when the user email is valid" do context "when the user has the right to access this project" do context "when the ticket uid is valid" do .... describe "#handle" do end describe "#handle" do context "when it is a valid email" do it "creates a comment" end context "when it is a invalid email" do it "doesn't create a comment" end end Saturday, November 23, 13
  98. it "creates a comment" do EmailHandler#handle describe "#handle" do context

    "when it is a valid email" do end end Saturday, November 23, 13
  99. it "creates a comment" do EmailHandler#handle describe "#handle" do context

    "when it is a valid email" do end end let(:email_handler) { EmailHandler.new(....) } Saturday, November 23, 13
  100. it "creates a comment" do EmailHandler#handle describe "#handle" do context

    "when it is a valid email" do end end let(:email_handler) { EmailHandler.new(....) } Saturday, November 23, 13
  101. it "creates a comment" do EmailHandler#handle describe "#handle" do context

    "when it is a valid email" do end end let(:email_handler) { EmailHandler.new(....) } before { email_handler.stub(:valid_email?).and_return(true) } Saturday, November 23, 13
  102. it "creates a comment" do EmailHandler#handle describe "#handle" do context

    "when it is a valid email" do end end let(:email_handler) { EmailHandler.new(....) } before { email_handler.stub(:valid_email?).and_return(true) } email_hander.handle Saturday, November 23, 13
  103. it "creates a comment" do EmailHandler#handle describe "#handle" do context

    "when it is a valid email" do end end let(:email_handler) { EmailHandler.new(....) } before { email_handler.stub(:valid_email?).and_return(true) } email_hander.handle Comment.count.should == 1 Saturday, November 23, 13
  104. it "creates a comment" do EmailHandler#handle describe "#handle" do context

    "when it is a valid email" do end end let(:email_handler) { EmailHandler.new(....) } before { email_handler.stub(:valid_email?).and_return(true) } email_hander.handle Comment.count.should == 1 context "when it is a invalid email" do let(:email_handler) { EmailHandler.new(....) } before { email_handler.stub(:valid_email?).and_return(false) } it "doesn't create a comment" do email_hander.handle Comment.count.should == 0 end end Saturday, November 23, 13
  105. class EmailHandler def initialize end def handle if valid_email? #create

    comment end end def valid_email? #validate the email information. end end EmailHandler#handle Saturday, November 23, 13
  106. class EmailHandler def initialize end def handle if valid_email? #create

    comment end end def valid_email? #validate the email information. end end EmailHandler#handle Saturday, November 23, 13
  107. class EmailHandler def initialize end def handle if valid_email? #create

    comment end end def valid_email? #validate the email information. end end EmailHandler#handle Saturday, November 23, 13
  108. class EmailHandler def initialize end def handle if valid_email? #create

    comment end end def valid_email? #validate the email information. end end EmailHandler#handle describe "#valid_email?" do end Saturday, November 23, 13
  109. class EmailHandler def initialize end def handle if valid_email? #create

    comment end end def valid_email? #validate the email information. end end EmailHandler#handle describe "#valid_email?" do context "all objects is valid" #true context "invalid project" #false context "invalid user" #false context "invalid ticket" #false end Saturday, November 23, 13
  110. What we got class EmailHandler def initialize end def handle

    if self.valid_email? #create comment end end def valid_email? #validate the email. end end class EmailRepliesController < AC def create if post_request_authenticated? EmailHandler.new(params).handle head(200) else head(422) end end def post_request_authenticated? ... end end Saturday, November 23, 13
  111. Controller EmailHandler handle valid_email? Mock Stub Mock and Stub Mock:

    Command method. Stub: Query method. Saturday, November 23, 13
  112. Controller EmailHandler handle valid_email? Mock Stub Mock and Stub Mock:

    Command method. Stub: Query method. Mock is brittle. Saturday, November 23, 13
  113. Controller EmailHandler handle valid_email? Mock Stub Mock and Stub Mock:

    Command method. Stub: Query method. Mock is brittle. Integrate Test Saturday, November 23, 13
  114. Benefits SendCloud Controller EmailHandler handle valid_email? Comment Project Ticket User

    * Test could be a documentation. Saturday, November 23, 13
  115. Benefits SendCloud Controller EmailHandler handle valid_email? Comment Project Ticket User

    * Test could be a documentation. * Flexible Api. Saturday, November 23, 13
  116. Benefits SendCloud Controller EmailHandler handle valid_email? Comment Project Ticket User

    * Test could be a documentation. * Flexible Api. Changed? Saturday, November 23, 13
  117. Benefits SendCloud Controller EmailHandler handle valid_email? Comment Project Ticket User

    Mock * Test could be a documentation. * Flexible Api. Changed? Saturday, November 23, 13
  118. Benefits SendCloud Controller EmailHandler handle valid_email? Comment Project Ticket User

    Mock Isolate * Test could be a documentation. * Flexible Api. Changed? Saturday, November 23, 13
  119. Benefits SendCloud Controller EmailHandler handle valid_email? Comment Project Ticket User

    Mock Isolate * Test could be a documentation. * Flexible Api. Changed? New Object Saturday, November 23, 13
  120. Benefits SendCloud Controller EmailHandler handle valid_email? Comment Project Ticket User

    Mock Isolate * Test could be a documentation. * Flexible Api. Changed? New Object Changed? Saturday, November 23, 13
  121. Benefits SendCloud Controller EmailHandler handle valid_email? Comment Project Ticket User

    Mock Stub Isolate * Test could be a documentation. * Flexible Api. Changed? New Object Changed? Saturday, November 23, 13
  122. Benefits SendCloud Controller EmailHandler handle valid_email? Comment Project Ticket User

    Mock Stub Isolate Isolate * Test could be a documentation. * Flexible Api. Changed? New Object Changed? Saturday, November 23, 13
  123. Benefits SendCloud Controller EmailHandler handle valid_email? Comment Project Ticket User

    Mock Stub Isolate Isolate * Test could be a documentation. * Flexible Api. Changed? New Object Changed? Changed? Saturday, November 23, 13
  124. Benefits SendCloud Controller EmailHandler handle valid_email? Comment Project Ticket User

    Mock Stub Isolate Isolate Isolate * Test could be a documentation. * Flexible Api. Changed? New Object Changed? Changed? Saturday, November 23, 13
  125. Benefits SendCloud Controller EmailHandler handle valid_email? Comment Project Ticket User

    Mock Stub Isolate Isolate Isolate * Test could be a documentation. * Flexible Api. Changed? New Object New Object Changed? Changed? Saturday, November 23, 13
  126. Example & Principles Boss B A C D Customer Boss

    Customer Saturday, November 23, 13
  127. Example & Principles Boss B A C D Customer Boss

    Customer Department Saturday, November 23, 13
  128. Example & Principles Boss B A C D Customer Boss

    Customer Department Alice Bob Saturday, November 23, 13
  129. Example & Principles Boss B A C D Customer Boss

    Customer Department Alice Bob A Saturday, November 23, 13
  130. Example & Principles Boss B A C D Customer Boss

    Customer Department Alice Bob A B C Saturday, November 23, 13
  131. Example & Principles Boss B A C D Customer Boss

    Customer Department Alice Bob A B C Doing too many things Saturday, November 23, 13
  132. Example & Principles Boss B A C D Customer Boss

    Customer Department Alice Bob A B C Doing too many things Single Responsibility Principle Saturday, November 23, 13
  133. Example & Principles Boss B A C D Customer Boss

    Customer Department Alice Bob A B C too much details Doing too many things Single Responsibility Principle Saturday, November 23, 13
  134. Example & Principles Boss B A C D Customer Boss

    Customer Department Alice Bob A B C too much details Tell Doing too many things Single Responsibility Principle Saturday, November 23, 13
  135. Review When do we to refactor code? What do we

    need to refactor? Saturday, November 23, 13
  136. Review Test guides us go forward. When do we to

    refactor code? What do we need to refactor? Saturday, November 23, 13
  137. Review Test guides us go forward. We begin to refactor

    when we feel pain in Test. When do we to refactor code? What do we need to refactor? Saturday, November 23, 13
  138. Review Test guides us go forward. We begin to refactor

    when we feel pain in Test. When do we to refactor code? What do we need to refactor? We reduce the dependencies found by Test. Saturday, November 23, 13