SlideShare a Scribd company logo
5 years know-how of


RSpec driven
Rails app.
development
      MOROHASHI Kyosuke
          (@moro)
Kyosuke
     MOROHASHI
✓ http://twitter.com/moro
✓ http://github.com/moro
✓ Eiwa System
  Management, Inc.
Test Context Arrangement Recipebook
http://gihyo.jp/news/report/01/rubykaigi2011/0001
aigi
                                byK rice
                             Ru l p
                                cia off
                             spe %
                                40




http://tatsu-zine.com/books/cuke
able o
                               vail -D
                              A
                                Ju nku igi
                              @ yKa
                               Rub




http://amzn.to/rails3recipebook
http://www.junkudo.co.jp/tenpo/
evtalk.html#20110721ikebukuro
5 years know-how of


RSpec driven
Rails app.
development
      MOROHASHI Kyosuke
          (@moro)
Test Context
Arrangement
       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 data!!

 ✓ Use multi strategies for multi
  types of data.
✓It seems good but less DRY. Is there any idea?

 ✓ Share your testing context.
m
    le
  ob
Pr




           What test
            should
         I write first?
on
    ti
  lu
So




           Write Model
            unit test.
People say




Skinny 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
                              spe %
                                 40

  Use Cucumber
     (or other end-to-end testing)

 to cover controller,
  views and more.
http://tatsu-zine.com/books/cuke
Model unit test
m
    le
  ob
Pr




   Began model test,
   but it’s difficult to
   setup data!!
events                students


courses   lessons   registrations


      rooms     periods
Course-1        Course-2

Period-1   Lesson-1-1      Lesson-2-1

Period-2   Lesson-1-2      Lesson-2-2

Period-3   Lesson-1-3      Lesson-2-3

Period-4   Lesson-1-4      Lesson-2-4

Period-5   Lesson-1-5      Lesson-2-5


            registration
Course-1        Course-2

Period-1   Lesson-1-1      Lesson-2-1

Period-2   Lesson-1-2      Lesson-2-2

Period-3   Lesson-1-3      Lesson-2-3

Period-4   Lesson-1-4      Lesson-2-4

Period-5   Lesson-1-5      Lesson-2-5


            registration
Course-1        Course-2

Period-1   Lesson-1-1      Lesson-2-1

Period-2   Lesson-1-2      Lesson-2-2

Period-3   Lesson-1-3      Lesson-2-3

Period-4   Lesson-1-4      Lesson-2-4

Period-5   Lesson-1-5      Lesson-2-5


            registration
Test Context Arrangement Recipebook
Test Context Arrangement Recipebook
Test Context Arrangement Recipebook
on
    ti
  lu


      Use multi
So




      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
Fixture
http://flic.kr/p/5NfjKM
✓ good speed to be
  loaded.
✓ less maintainability.
✓ less flexibility.
Fixture
  Replacement
http://fabricationgem.org/
✓ flexible.
✓ powerful but
  difficult to use
  correctly.
✓ slow to be loaded.
Test Context Arrangement Recipebook
Which should we use
rails-fixture or fixture
replacement?
Use them both which
suitable 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


                                               Master
  fixture     best     wrong        wrong
                                                data

   fixture                                      Resource
             wrong     good         best
replacements                                     data
                                     good
                                   for each     Event
  before()    good    best          wrong
                                    for all
                                                 data
events                 students
          Resource


courses   lessons    registrations
                          Event
      rooms     periods
          Master
Test Context Arrangement Recipebook
on
    ti
  lu


      Use multi
So




      strategies for
      multi types of
      data.
Test Context Arrangement Recipebook
✓ fixture
✓ fixture replacement
✓               block

Use them all which
suitable for the data.
m
    le
         It seems good
  ob
Pr




         but less DRY.
         Is there any
         idea?
Students
             Course      Count
Period-1   Lesson-1-1      2

Period-2   Lesson-1-2      3

Period-3   Lesson-1-3      3

Period-4   Lesson-1-4      3

Period-5   Lesson-1-5      2
Test Context Arrangement Recipebook
Test Context Arrangement Recipebook
Test Context Arrangement Recipebook
on
    ti
  lu
So




   Share your
 testing context.
https://github.com/rspec
✓ naming each
✓ naming them
✓ naming each
✓ naming them
“
Generates a method whose
return value is memoized
after the first call.
✓ name each
  focusing object.
✓ Build strategy
  doesn’t matter.
✓ naming each
✓ naming them
✓ RSpec’s

✓
✓
Test Context Arrangement Recipebook
A student subscribes a course
 event



                 lesson-1-1
                  lesson-1-1
course-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
Test Context Arrangement Recipebook
Test Context Arrangement Recipebook
✓ naming each w/
✓ naming them w/


Express your intention
clearly and reduce
tiredness to add new test.
on
    ti
  lu
So




   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 data!!

 ✓ Use multi strategies for multi
  types of data.
✓It seems good but less DRY. Is there any idea?

 ✓ Share your testing context.
✓ fixture
✓ fixture replacement
✓               block

Use them all which
suitable for the data.
✓ naming each w/
✓ naming them w/


Express your intention
clearly and reduce
tiredness to add new test.
May a test
be with you.
Test Context Arrangement Recipebook
http://www.rubyworld-conf.org/
May a test
be with you.

More Related Content

PDF
Rk10trailer
PDF
超絶技巧 Ruby プログラミング - Esoteric, Obfuscated Ruby Programming
KEY
Testing smells
PPTX
2014 toronto-torbug
PDF
flowr streamlining computing workflows
PDF
beyond-regular-regular-expressions-v20.pdf
PPTX
2014 nicta-reproducibility
PDF
Natural Language Processing using Java
Rk10trailer
超絶技巧 Ruby プログラミング - Esoteric, Obfuscated Ruby Programming
Testing smells
2014 toronto-torbug
flowr streamlining computing workflows
beyond-regular-regular-expressions-v20.pdf
2014 nicta-reproducibility
Natural Language Processing using Java

Similar to Test Context Arrangement Recipebook (20)

PDF
Self training improves_nlu
PPTX
The Data Analysis Workflow
PPTX
Recurrent Neural Networks for Text Analysis
PDF
Mimmit Koodaa - Testiautomaatio on testauksen dokumentointia
PDF
Online Consumer Panel simulator - First Version demo: Sampling Operations Ana...
PDF
Clean tests
PDF
Scalable and Available, Patterns for Success
PDF
PuppetConf 2016: Enjoying the Journey from Puppet 3.x to 4.x – Rob Nelson, AT&T
PPT
Overfitting and-tbl
PDF
Magical Methods for Batch Data Processing
PDF
Ken Bragg: Batch data processing in FME
PPTX
Jonathan Coveney: Why Pig?
PDF
Meetup 06/2015 - @testsetup
PDF
MSR 2009
PPT
Writing Maintainable Code
PPT
Writing maintainable Oracle PL/SQL code
KEY
QwalKeko, a History Querying Tool
PPTX
Decoupling shared code with state that needs to cleared in between uses
PDF
Kostiantyn Omelianchuk, Oleksandr Skurzhanskyi "Building a state-of-the-art a...
PPTX
Spark Application Development Made Easy
Self training improves_nlu
The Data Analysis Workflow
Recurrent Neural Networks for Text Analysis
Mimmit Koodaa - Testiautomaatio on testauksen dokumentointia
Online Consumer Panel simulator - First Version demo: Sampling Operations Ana...
Clean tests
Scalable and Available, Patterns for Success
PuppetConf 2016: Enjoying the Journey from Puppet 3.x to 4.x – Rob Nelson, AT&T
Overfitting and-tbl
Magical Methods for Batch Data Processing
Ken Bragg: Batch data processing in FME
Jonathan Coveney: Why Pig?
Meetup 06/2015 - @testsetup
MSR 2009
Writing Maintainable Code
Writing maintainable Oracle PL/SQL code
QwalKeko, a History Querying Tool
Decoupling shared code with state that needs to cleared in between uses
Kostiantyn Omelianchuk, Oleksandr Skurzhanskyi "Building a state-of-the-art a...
Spark Application Development Made Easy
Ad

More from Kyosuke MOROHASHI (13)

PDF
Introduction HTTP via cURL
PDF
Ruby ecosystem applied to agile project
PDF
Begin cucumber-in-real-world
PDF
Cucumber in Practice(en)
PDF
Rails testing environment, 2009 fall
PDF
TDD frameworks let me dream "Project Specific Language"
PDF
Rails Tokyo 035 Cucumber
PDF
OSC2008 勉強会大集合 Rails勉強会@東京
PDF
Capistrano in practice - WebCareer
PDF
named_scope more detail - WebCareer
PDF
named_scope more detail
PDF
Rails <form> Chronicle
PDF
そうだ勉強会に行こう
Introduction HTTP via cURL
Ruby ecosystem applied to agile project
Begin cucumber-in-real-world
Cucumber in Practice(en)
Rails testing environment, 2009 fall
TDD frameworks let me dream "Project Specific Language"
Rails Tokyo 035 Cucumber
OSC2008 勉強会大集合 Rails勉強会@東京
Capistrano in practice - WebCareer
named_scope more detail - WebCareer
named_scope more detail
Rails <form> Chronicle
そうだ勉強会に行こう
Ad

Recently uploaded (20)

PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
Cell Types and Its function , kingdom of life
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
PDF
Insiders guide to clinical Medicine.pdf
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
Pre independence Education in Inndia.pdf
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PPTX
Institutional Correction lecture only . . .
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
STATICS OF THE RIGID BODIES Hibbelers.pdf
Abdominal Access Techniques with Prof. Dr. R K Mishra
Cell Types and Its function , kingdom of life
Final Presentation General Medicine 03-08-2024.pptx
Supply Chain Operations Speaking Notes -ICLT Program
102 student loan defaulters named and shamed – Is someone you know on the list?
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
Insiders guide to clinical Medicine.pdf
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Anesthesia in Laparoscopic Surgery in India
VCE English Exam - Section C Student Revision Booklet
2.FourierTransform-ShortQuestionswithAnswers.pdf
O7-L3 Supply Chain Operations - ICLT Program
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Pre independence Education in Inndia.pdf
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
Week 4 Term 3 Study Techniques revisited.pptx
Institutional Correction lecture only . . .

Test Context Arrangement Recipebook