5 years know-how ofRSpec drivenRails app.development      MOROHASHI Kyosuke          (@moro)
Kyosuke     MOROHASHI✓ http://twitter.com/moro✓ http://github.com/moro✓ Eiwa System  Management, Inc.
http://gihyo.jp/news/report/01/rubykaigi2011/0001
aigi                                byK rice                             Ru l p                                cia off    ...
able o                               vail -D                              A                                Ju nku igi     ...
http://www.junkudo.co.jp/tenpo/evtalk.html#20110721ikebukuro
5 years know-how ofRSpec drivenRails app.development      MOROHASHI Kyosuke          (@moro)
Test ContextArrangement       3
I’ll talk about.✓What test should I write first? ✓ Write model unit test.✓I began model test,but it’s difficult to setup dat...
m    le  obPr           What test            should         I write first?
on    ti  luSo           Write Model            unit test.
People saySkinny Controllers    Fat Models
It’s clear what      happening.http://flic.kr/p/5tk4by
#64 2011-07-18 12:00  http://twitter.com/railstokyo
aigi                                 byK rice                              Ru l p                                 cia off ...
Model unit test
m    le  obPr   Began model test,   but it’s difficult to   setup data!!
events                studentscourses   lessons   registrations      rooms     periods
Course-1        Course-2Period-1   Lesson-1-1      Lesson-2-1Period-2   Lesson-1-2      Lesson-2-2Period-3   Lesson-1-3   ...
Course-1        Course-2Period-1   Lesson-1-1      Lesson-2-1Period-2   Lesson-1-2      Lesson-2-2Period-3   Lesson-1-3   ...
Course-1        Course-2Period-1   Lesson-1-1      Lesson-2-1Period-2   Lesson-1-2      Lesson-2-2Period-3   Lesson-1-3   ...
on    ti  lu      Use multiSo      strategies for      multi types of      data.
✓ 3 types of data✓ 3 strategies
✓ 3 types of data✓ 3 strategies
✓ Master data✓ Resource data✓ Event data
Mastar data✓ Created/updated rarely. ✓e.g. rooms / periods.✓ Less dependencies to others.✓ Maintained by             or so.
Resource data✓ Mainly created/updated  data.✓ Users themselves  maintains this type of data.
Event data✓ Represent relationship  between resources.✓ Used for  ‘s through table in Rails.
✓ 3 types of data✓ 3 strategies
✓ Fixture✓ Fixture replacement✓              block
Fixturehttp://flic.kr/p/5NfjKM
✓ good speed to be  loaded.✓ less maintainability.✓ less flexibility.
Fixture  Replacementhttp://fabricationgem.org/
✓ flexible.✓ powerful but  difficult to use  correctly.✓ slow to be loaded.
Which should we userails-fixture or fixturereplacement?Use them both whichsuitable for the data.
block
✓ each run per test.✓ same speed with real data persistence.✓ edit each of them  to maintain.
flexibility   maintain-              speed                       in test      ability     good for                         ...
events                 students          Resourcecourses   lessons    registrations                          Event      ro...
on    ti  lu      Use multiSo      strategies for      multi types of      data.
✓ fixture✓ fixture replacement✓               blockUse them all whichsuitable for the data.
m    le         It seems good  obPr         but less DRY.         Is there any         idea?
Students             Course      CountPeriod-1   Lesson-1-1      2Period-2   Lesson-1-2      3Period-3   Lesson-1-3      3...
on    ti  luSo   Share your testing context.
https://github.com/rspec
✓ naming each✓ naming them
✓ naming each✓ naming them
“Generates a method whosereturn value is memoizedafter the first call.
✓ name each  focusing object.✓ Build strategy  doesn’t matter.
✓ naming each✓ naming them
✓ RSpec’s✓✓
A student subscribes a course event                 lesson-1-1                  lesson-1-1course-1           lesson-1-1   ...
✓ naming each w/✓ naming them w/Express your intentionclearly and reducetiredness to add new test.
on    ti  luSo   Share your testing context.
Conclusion
I’ve talked about.✓What test should I write first? ✓ Write model unit test.✓I began model test,but it’s difficult to setup d...
✓ fixture✓ fixture replacement✓               blockUse them all whichsuitable for the data.
✓ naming each w/✓ naming them w/Express your intentionclearly and reducetiredness to add new test.
May a testbe with you.
http://www.rubyworld-conf.org/
May a testbe with you.
Test Context Arrangement Recipebook
Test Context Arrangement Recipebook
Test Context Arrangement Recipebook
Test Context Arrangement Recipebook
Test Context Arrangement Recipebook
Test Context Arrangement Recipebook
Test Context Arrangement Recipebook
Test Context Arrangement Recipebook
Test Context Arrangement Recipebook
Test Context Arrangement Recipebook
Test Context Arrangement Recipebook
Test Context Arrangement Recipebook
Test Context Arrangement Recipebook
Test Context Arrangement Recipebook
Upcoming SlideShare
Loading in …5
×

Test Context Arrangement Recipebook

7,294 views

Published on

Published in: Education, Technology
0 Comments
14 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
7,294
On SlideShare
0
From Embeds
0
Number of Embeds
1,737
Actions
Shares
0
Downloads
58
Comments
0
Likes
14
Embeds 0
No embeds

No notes for slide

Test Context Arrangement Recipebook

  1. 1. 5 years know-how ofRSpec drivenRails app.development MOROHASHI Kyosuke (@moro)
  2. 2. Kyosuke MOROHASHI✓ http://twitter.com/moro✓ http://github.com/moro✓ Eiwa System Management, Inc.
  3. 3. http://gihyo.jp/news/report/01/rubykaigi2011/0001
  4. 4. aigi byK rice Ru l p cia off spe % 40http://tatsu-zine.com/books/cuke
  5. 5. able o vail -D A Ju nku igi @ yKa Rubhttp://amzn.to/rails3recipebook
  6. 6. http://www.junkudo.co.jp/tenpo/evtalk.html#20110721ikebukuro
  7. 7. 5 years know-how ofRSpec drivenRails app.development MOROHASHI Kyosuke (@moro)
  8. 8. Test ContextArrangement 3
  9. 9. I’ll talk about.✓What test should I write first? ✓ Write model unit test.✓I began model test,but it’s difficult to setup data!! ✓ Use multi strategies for multi types of data.✓It seems good but less DRY. Is there any idea? ✓ Share your testing context.
  10. 10. m le obPr What test should I write first?
  11. 11. on ti luSo Write Model unit test.
  12. 12. People saySkinny Controllers Fat Models
  13. 13. It’s clear what happening.http://flic.kr/p/5tk4by
  14. 14. #64 2011-07-18 12:00 http://twitter.com/railstokyo
  15. 15. aigi byK rice Ru l p cia off spe % 40 Use Cucumber (or other end-to-end testing) to cover controller, views and more.http://tatsu-zine.com/books/cuke
  16. 16. Model unit test
  17. 17. m le obPr Began model test, but it’s difficult to setup data!!
  18. 18. events studentscourses lessons registrations rooms periods
  19. 19. Course-1 Course-2Period-1 Lesson-1-1 Lesson-2-1Period-2 Lesson-1-2 Lesson-2-2Period-3 Lesson-1-3 Lesson-2-3Period-4 Lesson-1-4 Lesson-2-4Period-5 Lesson-1-5 Lesson-2-5 registration
  20. 20. Course-1 Course-2Period-1 Lesson-1-1 Lesson-2-1Period-2 Lesson-1-2 Lesson-2-2Period-3 Lesson-1-3 Lesson-2-3Period-4 Lesson-1-4 Lesson-2-4Period-5 Lesson-1-5 Lesson-2-5 registration
  21. 21. Course-1 Course-2Period-1 Lesson-1-1 Lesson-2-1Period-2 Lesson-1-2 Lesson-2-2Period-3 Lesson-1-3 Lesson-2-3Period-4 Lesson-1-4 Lesson-2-4Period-5 Lesson-1-5 Lesson-2-5 registration
  22. 22. on ti lu Use multiSo strategies for multi types of data.
  23. 23. ✓ 3 types of data✓ 3 strategies
  24. 24. ✓ 3 types of data✓ 3 strategies
  25. 25. ✓ Master data✓ Resource data✓ Event data
  26. 26. Mastar data✓ Created/updated rarely. ✓e.g. rooms / periods.✓ Less dependencies to others.✓ Maintained by or so.
  27. 27. Resource data✓ Mainly created/updated data.✓ Users themselves maintains this type of data.
  28. 28. Event data✓ Represent relationship between resources.✓ Used for ‘s through table in Rails.
  29. 29. ✓ 3 types of data✓ 3 strategies
  30. 30. ✓ Fixture✓ Fixture replacement✓ block
  31. 31. Fixturehttp://flic.kr/p/5NfjKM
  32. 32. ✓ good speed to be loaded.✓ less maintainability.✓ less flexibility.
  33. 33. Fixture Replacementhttp://fabricationgem.org/
  34. 34. ✓ flexible.✓ powerful but difficult to use correctly.✓ slow to be loaded.
  35. 35. Which should we userails-fixture or fixturereplacement?Use them both whichsuitable for the data.
  36. 36. block
  37. 37. ✓ each run per test.✓ same speed with real data persistence.✓ edit each of them to maintain.
  38. 38. flexibility maintain- speed in test ability good for Master fixture best wrong wrong data fixture Resource wrong good bestreplacements data good for each Event before() good best wrong for all data
  39. 39. events students Resourcecourses lessons registrations Event rooms periods Master
  40. 40. on ti lu Use multiSo strategies for multi types of data.
  41. 41. ✓ fixture✓ fixture replacement✓ blockUse them all whichsuitable for the data.
  42. 42. m le It seems good obPr but less DRY. Is there any idea?
  43. 43. Students Course CountPeriod-1 Lesson-1-1 2Period-2 Lesson-1-2 3Period-3 Lesson-1-3 3Period-4 Lesson-1-4 3Period-5 Lesson-1-5 2
  44. 44. on ti luSo Share your testing context.
  45. 45. https://github.com/rspec
  46. 46. ✓ naming each✓ naming them
  47. 47. ✓ naming each✓ naming them
  48. 48. “Generates a method whosereturn value is memoizedafter the first call.
  49. 49. ✓ name each focusing object.✓ Build strategy doesn’t matter.
  50. 50. ✓ naming each✓ naming them
  51. 51. ✓ RSpec’s✓✓
  52. 52. A student subscribes a course event lesson-1-1 lesson-1-1course-1 lesson-1-1 lesson-1-1 lesson-1-1 registrations registrations registrations registrations Alice <student> room-1 room-1 period-1 period-1 room-1 room-1 period-1 period-1 room-1 period-1 course-2 lesson-2-1 lesson-2-1 lesson-2-1 lesson-2-1 lesson-2-1
  53. 53. ✓ naming each w/✓ naming them w/Express your intentionclearly and reducetiredness to add new test.
  54. 54. on ti luSo Share your testing context.
  55. 55. Conclusion
  56. 56. I’ve talked about.✓What test should I write first? ✓ Write model unit test.✓I began model test,but it’s difficult to setup data!! ✓ Use multi strategies for multi types of data.✓It seems good but less DRY. Is there any idea? ✓ Share your testing context.
  57. 57. ✓ fixture✓ fixture replacement✓ blockUse them all whichsuitable for the data.
  58. 58. ✓ naming each w/✓ naming them w/Express your intentionclearly and reducetiredness to add new test.
  59. 59. May a testbe with you.
  60. 60. http://www.rubyworld-conf.org/
  61. 61. May a testbe with you.

×