SlideShare a Scribd company logo
1 of 32
Download to read offline
RS  pMy
              e c
            Best
         Practice
13年2月3日日曜日
make
    GOOD     LET
    use of

13年2月3日日曜日
pl e s
       e x a m
13年2月3日日曜日
describe User do
               describe '#admin?' do




                                                        s
                 subject { user.admin? }




                                                    l e
                 context "when user is administrator" do




                                                   p
                   let(:user) do
                     FactoryGirl.create :user, admin: true




             m
                   end




           a
                   it "returns true" do




         x
                     expect(subject).to be_true




       e
                   end
                 end

                 context "when user is not administrator" do
                   let(:user) do
                     FactoryGirl.create :user, admin: false
                   end

                   it "returns false" do
                     expect(subject).to be_false
                   end
                 end
               end


13年2月3日日曜日
describe User do
               describe '#admin?' do




                                                        s
                 subject { user.admin? }




                                                    l e
                 context "when user is administrator" do




                                                   p
                   let(:user) do
                     FactoryGirl.create :user, admin: true




             m
                   end




           a
                   it "returns true" do




         x
                     expect(subject).to be_true




       e
                   end
                 end

                 context "when user is not administrator" do
                   let(:user) do
                     FactoryGirl.create :user, admin: false
                   end

                   it "returns false" do
                     expect(subject).to be_false
                   end
                 end
               end


13年2月3日日曜日
describe User do
               describe '#admin?' do




                                                        s
                 subject { user.admin? }




                                                    l e
                 context "when user is administrator" do




NOTmDRY                                            p
                   let(:user) do
                     FactoryGirl.create :user, admin: true
                   end




     a
                   it "returns true" do




   x
                     expect(subject).to be_true




 e
                   end
                 end

                 context "when user is not administrator" do
                   let(:user) do
                     FactoryGirl.create :user, admin: false
                   end

                   it "returns false" do
                     expect(subject).to be_false
                   end
                 end
               end


13年2月3日日曜日
Using LET for           ★

    Defining
        ★
                    n t e x t
             ★

                 C o
13年2月3日日曜日
describe User do
               describe '#admin?' do




                                                        s
                 subject { user.admin? }




                                                    l e
                 context "when user is administrator" do




                                                   p
                   let(:user) do
                     FactoryGirl.create :user, admin: true




             m
                   end




           a
                   it "returns true" do




         x
                     expect(subject).to be_true




       e
                   end
                 end

                 context "when user is not administrator" do
                   let(:user) do
                     FactoryGirl.create :user, admin: false
                   end

                   it "returns false" do
                     expect(subject).to be_false
                   end
                 end
               end


13年2月3日日曜日
describe User do
               describe '#admin?' do




                                                        s
                 subject { user.admin? }




                                                    l e
                 let(:user) { FactoryGirl.create :user, admin: admin }




                                                   p
                 context "when user is administrator" do




             m
                   let(:admin) { true }




           a
                   it "returns true" do




         x
                     expect(subject).to be_true




       e
                   end
                 end

                 context "when user is not administrator" do
                   let(:admin) { false }

                   it "returns false" do
                     expect(subject).to be_false
                   end
                 end
               end
             end



13年2月3日日曜日
describe User do
                 describe '#admin?' do




                                                          s
                   subject { user.admin? }




                                                        e
             context "when user is administrator" do



                                                      l
                 let(:user) { FactoryGirl.create :user, admin: admin }
               let(:admin) { true }


                                                     p
                   context "when user is administrator" do




             m
                     let(:admin) { true }
               it "returnstrue" do do
                                 true"



           a
                   it "returns
                 expect(subject).to be_true


         x
                     expect(subject).to be_true




       e
                   end
               end
                 end
             end context "when user is not administrator" do
                     let(:admin) { false }

                     it "returns false" do
                       expect(subject).to be_false
                     end
 Write ONLY changing parameters under ‘context’.
                   end
                 end
 By doing so, the spec is very clear and meaningful.
               end



13年2月3日日曜日
describe User do
               describe '#admin?' do




                    s
                 subject { user.admin? }




                l e
                 let(:user) { FactoryGirl.create :user, admin: admin }




       HOW TO  p
                 context "when user is administrator" do




             m
                   let(:admin) { true }




           a
                   it "returns true" do




         x
                     expect(subject).to be_true




       e
                   end
                 end

                 context "when user is not administrator" do
                   let(:admin) { false }

                   it "returns false" do
                     expect(subject).to be_false
                   end
                 end
               end
             end



13年2月3日日曜日
describe User do
               describe '#admin?' do




                                                        s
                 subject { user.admin? }




                                                    l e
 let(:user) let(:user) { FactoryGirl.create :user, admin: }admin }
            { FactoryGirl.create :user, admin: admin



                                                   p
                 context "when user is administrator" do




             m
                   let(:admin) { true }




           a
                   it "returns true" do




         x
                     expect(subject).to be_true




       e
                   end
                 end

                 context "when user is not administrator" do
                   let(:admin) { false }

                   it "returns false" do

★ Prepare resources using ‘let’, ‘let!’
                     expect(subject).to be_false
                   end
                 end
               end

       and ‘before’ under describe.
             end



13年2月3日日曜日
describe User do
               describe '#admin?' do




                                                        s
                 subject { user.admin? }




                                                    l e
 let(:user) let(:user) { FactoryGirl.create :user, admin: }admin }
            { FactoryGirl.create :user, admin: admin



                                                   p
                 context "when user is administrator" do




             m
                   let(:admin) { true }




           a
                   it "returns true" do




         x
                     expect(subject).to be_true




       e
                   end
                 end

                 context "when user is not administrator" do
                   let(:admin) { false }

                   it "returns false" do
                     expect(subject).to be_false
★ Parameters changes in context is defined by ‘let’
                   end
                 end
               end
     under context, and use ONLY let at there.
             end



13年2月3日日曜日
describe User do
               describe '#admin?' do




                                                        s
                 subject { user.admin? }




                                                    l e
                 let(:user) { FactoryGirl.create :user, admin: admin }
      context "when user is administrator" do



                                                   p
        let(:admin) "when user is}administrator" do
              context { true }




             m
                let(:admin) { true




           a
                   it "returns true" do




         x
                     expect(subject).to be_true




       e
                   end
                 end
     context "when user is not administrator" do
       let(:admin) { false is not administrator" do
              context "when user }
                   let(:admin) { false }

                   it "returns false" do
                     expect(subject).to be_false
★ Parameters changes in ‘context’ is defined by
                   end
                 end
               end
     ‘let’ under context, and use ONLY ‘let’ at there.
             end



13年2月3日日曜日
describe User do
               describe '#admin?' do




                    s
                 subject { user.admin? }




                l e
                 let(:user) { FactoryGirl.create :user, admin: admin }




               p
       MECHANISM
                 context "when user is administrator" do




             m
                   let(:admin) { true }




           a
                   it "returns true" do




         x
                     expect(subject).to be_true




       e
                   end
                 end

                 context "when user is not administrator" do
                   let(:admin) { false }

                   it "returns false" do
                     expect(subject).to be_false
                   end
                 end
               end
             end



13年2月3日日曜日
MEC
     Lazy    ISM
                                                                              HAN

     Evaluation
http://www.fanpop.com/clubs/ho-kago-tea-time/images/29622703/title/dont-lazy-wallpaper
13年2月3日日曜日
describe User do
               describe '#admin?' do




                                                        s
                 subject { user.admin? }




                                                    l e
                 let(:user) { FactoryGirl.create :user, admin: admin }




                                                   p
                 context "when user is administrator" do




             m
                   let(:admin) { true }




           a
                   it "returns true" do




         x
                     expect(subject).to be_true




       e
                   end
                 end

                 context "when user is not administrator" do
                   let(:admin) { false }

                   it "returns false" do
                     expect(subject).to be_false
                   end
                 end
               end
             end



13年2月3日日曜日
subject { user.admin? }




                                            s
             let(:user) do




                                        l e
               FactoryGirl.create :user, admin: admin




                                       p
             end




             m
             context "when user is administrator" do




           a
               let(:admin) { true }




       e x
               it "returns true" do
                 expect(subject).to be_true
               end
             end




13年2月3日日曜日
subject { user.admin? }




                                            s
             let(:user) do




                                        l e
               FactoryGirl.create :user, admin: admin




                                       p
             end




             m
             context "when user is administrator" do




           a
               let(:admin) { true }




       e x
               it "returns true" do
                 expect(subject).to be_true
               end
             end


 ★ At first, RSpec evaluates this line.
13年2月3日日曜日
subject { user.admin? }




                                            s
             let(:user) do




                                        l e
               FactoryGirl.create :user, admin: admin




                                       p
             end




             m
             context "when user is administrator" do




           a
               let(:admin) { true }




       e x
               it "returns true" do
                 expect(subject).to be_true
               end
             end


 ★ Then ‘subject’ is evaluated.
13年2月3日日曜日
subject { user.admin? }




                                            s
             let(:user) do




                                        l e
               FactoryGirl.create :user, admin: admin




                                       p
             end




             m
             context "when user is administrator" do




           a
               let(:admin) { true }




       e x
               it "returns true" do
                 expect(subject).to be_true
               end
             end

 ★ And ‘user’ defined by ‘let’
         is evaluated.
13年2月3日日曜日
subject { user.admin? }




                                            s
             let(:user) do




                                        l e
               FactoryGirl.create :user, admin: admin




                                       p
             end




             m
             context "when user is administrator" do




           a
               let(:admin) { true }




       e x
               it "returns true" do
                 expect(subject).to be_true
               end
             end

 ★ And ‘admin’ defined by ‘let’
         is evaluated.
13年2月3日日曜日
subject { user.admin? }




                                            s
             let(:user) do




                                        l e
               FactoryGirl.create :user, admin: admin




                                       p
             end
 FactoryGirl.create(:user, admin: true).admin?



             m
             context "when user is administrator" do




           a
               let(:admin) { true }




       e x
               it "returns true" do
                 expect(subject).to be_true
               end
             end

 ★ Finally, ‘subject’ is evaluated to
         this.
13年2月3日日曜日
describe User do
               describe '#admin?' do




                                                        s
                 subject { user.admin? }




                                                    l e
                 let(:user) { FactoryGirl.create :user, admin: admin }




                                                   p
                 context "when user is administrator" do




             m
                   let(:admin) { true }




           a
                   it "returns true" do




         x
                     expect(subject).to be_true




       e
                   end
                 end

                 context "when user is not administrator" do
                   let(:admin) { false }

                   it "returns false" do
                     expect(subject).to be_false
                   end
                 end
               end
             end



13年2月3日日曜日
Yes!!
     We Got
     Clear Spec
13年2月3日日曜日
CATION!!CATION!!CATION!!CATION!!
CATION!!CATION!!CATION!!CATION!!
CATION!!CATION!!CATION!!CATION!!
CATION!!CATION!!CATION!!CATION!!
CATION!!CATION!!CATION!!CATION!!
CATION!!CATION!!CATION!!CATION!!
CATION!!CATION!!CATION!!CATION!!
CATION!!CATION!!CATION!!CATION!!
CATION!!CATION!!CATION!!CATION!!
CATION!!CATION!!CATION!!CATION!!
13年2月3日日曜日
Using


     B u rd  n
      Lazy Evaluation
            e on
     Readers...

13年2月3日日曜日
IT’S
      TRADE-OFF

13年2月3日日曜日
To make
      DRY SPEC
      use a few
      Lazy Evaluation
13年2月3日日曜日
If
      there is many
      Lazy Evaluation,

13年2月3日日曜日
IT’S TIME TO
                                    IN G
                       T O R
               FA C
         R E     and it’s a very very fun time :p

13年2月3日日曜日
blogged at
      http://blog.tanaka51.jp/blog/2012/12/14/rspec-best-practice/



      referenced by
      https://speakerdeck.com/holman
      http://kotas.hatenablog.jp/entry/2012/11/22/000046




13年2月3日日曜日

More Related Content

Recently uploaded

2k Shots ≽ 9205541914 ≼ Call Girls In Palam (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Palam (Delhi)2k Shots ≽ 9205541914 ≼ Call Girls In Palam (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Palam (Delhi)Delhi Call girls
 
9892124323, Call Girls in mumbai, Vashi Call Girls , Kurla Call girls
9892124323, Call Girls in mumbai, Vashi Call Girls , Kurla Call girls9892124323, Call Girls in mumbai, Vashi Call Girls , Kurla Call girls
9892124323, Call Girls in mumbai, Vashi Call Girls , Kurla Call girlsPooja Nehwal
 
LC_YouSaidYes_NewBelieverBookletDone.pdf
LC_YouSaidYes_NewBelieverBookletDone.pdfLC_YouSaidYes_NewBelieverBookletDone.pdf
LC_YouSaidYes_NewBelieverBookletDone.pdfpastor83
 
2k Shots ≽ 9205541914 ≼ Call Girls In Dashrath Puri (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Dashrath Puri (Delhi)2k Shots ≽ 9205541914 ≼ Call Girls In Dashrath Puri (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Dashrath Puri (Delhi)Delhi Call girls
 
Pokemon Go... Unraveling the Conspiracy Theory
Pokemon Go... Unraveling the Conspiracy TheoryPokemon Go... Unraveling the Conspiracy Theory
Pokemon Go... Unraveling the Conspiracy Theorydrae5
 
$ Love Spells^ 💎 (310) 882-6330 in West Virginia, WV | Psychic Reading Best B...
$ Love Spells^ 💎 (310) 882-6330 in West Virginia, WV | Psychic Reading Best B...$ Love Spells^ 💎 (310) 882-6330 in West Virginia, WV | Psychic Reading Best B...
$ Love Spells^ 💎 (310) 882-6330 in West Virginia, WV | Psychic Reading Best B...PsychicRuben LoveSpells
 
8377087607 Full Enjoy @24/7-CLEAN-Call Girls In Chhatarpur,
8377087607 Full Enjoy @24/7-CLEAN-Call Girls In Chhatarpur,8377087607 Full Enjoy @24/7-CLEAN-Call Girls In Chhatarpur,
8377087607 Full Enjoy @24/7-CLEAN-Call Girls In Chhatarpur,dollysharma2066
 
Top Rated Pune Call Girls Tingre Nagar ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Tingre Nagar ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Tingre Nagar ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Tingre Nagar ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
2k Shots ≽ 9205541914 ≼ Call Girls In Mukherjee Nagar (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Mukherjee Nagar (Delhi)2k Shots ≽ 9205541914 ≼ Call Girls In Mukherjee Nagar (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Mukherjee Nagar (Delhi)Delhi Call girls
 
2k Shots ≽ 9205541914 ≼ Call Girls In Jasola (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Jasola (Delhi)2k Shots ≽ 9205541914 ≼ Call Girls In Jasola (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Jasola (Delhi)Delhi Call girls
 
The Selfspace Journal Preview by Mindbrush
The Selfspace Journal Preview by MindbrushThe Selfspace Journal Preview by Mindbrush
The Selfspace Journal Preview by MindbrushShivain97
 
WOMEN EMPOWERMENT women empowerment.pptx
WOMEN EMPOWERMENT women empowerment.pptxWOMEN EMPOWERMENT women empowerment.pptx
WOMEN EMPOWERMENT women empowerment.pptxpadhand000
 
call Now 9811711561 Cash Payment乂 Call Girls in Dwarka Mor
call Now 9811711561 Cash Payment乂 Call Girls in Dwarka Morcall Now 9811711561 Cash Payment乂 Call Girls in Dwarka Mor
call Now 9811711561 Cash Payment乂 Call Girls in Dwarka Morvikas rana
 

Recently uploaded (15)

2k Shots ≽ 9205541914 ≼ Call Girls In Palam (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Palam (Delhi)2k Shots ≽ 9205541914 ≼ Call Girls In Palam (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Palam (Delhi)
 
9892124323, Call Girls in mumbai, Vashi Call Girls , Kurla Call girls
9892124323, Call Girls in mumbai, Vashi Call Girls , Kurla Call girls9892124323, Call Girls in mumbai, Vashi Call Girls , Kurla Call girls
9892124323, Call Girls in mumbai, Vashi Call Girls , Kurla Call girls
 
LC_YouSaidYes_NewBelieverBookletDone.pdf
LC_YouSaidYes_NewBelieverBookletDone.pdfLC_YouSaidYes_NewBelieverBookletDone.pdf
LC_YouSaidYes_NewBelieverBookletDone.pdf
 
2k Shots ≽ 9205541914 ≼ Call Girls In Dashrath Puri (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Dashrath Puri (Delhi)2k Shots ≽ 9205541914 ≼ Call Girls In Dashrath Puri (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Dashrath Puri (Delhi)
 
Pokemon Go... Unraveling the Conspiracy Theory
Pokemon Go... Unraveling the Conspiracy TheoryPokemon Go... Unraveling the Conspiracy Theory
Pokemon Go... Unraveling the Conspiracy Theory
 
(Anamika) VIP Call Girls Navi Mumbai Call Now 8250077686 Navi Mumbai Escorts ...
(Anamika) VIP Call Girls Navi Mumbai Call Now 8250077686 Navi Mumbai Escorts ...(Anamika) VIP Call Girls Navi Mumbai Call Now 8250077686 Navi Mumbai Escorts ...
(Anamika) VIP Call Girls Navi Mumbai Call Now 8250077686 Navi Mumbai Escorts ...
 
$ Love Spells^ 💎 (310) 882-6330 in West Virginia, WV | Psychic Reading Best B...
$ Love Spells^ 💎 (310) 882-6330 in West Virginia, WV | Psychic Reading Best B...$ Love Spells^ 💎 (310) 882-6330 in West Virginia, WV | Psychic Reading Best B...
$ Love Spells^ 💎 (310) 882-6330 in West Virginia, WV | Psychic Reading Best B...
 
(Aarini) Russian Call Girls Surat Call Now 8250077686 Surat Escorts 24x7
(Aarini) Russian Call Girls Surat Call Now 8250077686 Surat Escorts 24x7(Aarini) Russian Call Girls Surat Call Now 8250077686 Surat Escorts 24x7
(Aarini) Russian Call Girls Surat Call Now 8250077686 Surat Escorts 24x7
 
8377087607 Full Enjoy @24/7-CLEAN-Call Girls In Chhatarpur,
8377087607 Full Enjoy @24/7-CLEAN-Call Girls In Chhatarpur,8377087607 Full Enjoy @24/7-CLEAN-Call Girls In Chhatarpur,
8377087607 Full Enjoy @24/7-CLEAN-Call Girls In Chhatarpur,
 
Top Rated Pune Call Girls Tingre Nagar ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Tingre Nagar ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Tingre Nagar ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Tingre Nagar ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
2k Shots ≽ 9205541914 ≼ Call Girls In Mukherjee Nagar (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Mukherjee Nagar (Delhi)2k Shots ≽ 9205541914 ≼ Call Girls In Mukherjee Nagar (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Mukherjee Nagar (Delhi)
 
2k Shots ≽ 9205541914 ≼ Call Girls In Jasola (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Jasola (Delhi)2k Shots ≽ 9205541914 ≼ Call Girls In Jasola (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Jasola (Delhi)
 
The Selfspace Journal Preview by Mindbrush
The Selfspace Journal Preview by MindbrushThe Selfspace Journal Preview by Mindbrush
The Selfspace Journal Preview by Mindbrush
 
WOMEN EMPOWERMENT women empowerment.pptx
WOMEN EMPOWERMENT women empowerment.pptxWOMEN EMPOWERMENT women empowerment.pptx
WOMEN EMPOWERMENT women empowerment.pptx
 
call Now 9811711561 Cash Payment乂 Call Girls in Dwarka Mor
call Now 9811711561 Cash Payment乂 Call Girls in Dwarka Morcall Now 9811711561 Cash Payment乂 Call Girls in Dwarka Mor
call Now 9811711561 Cash Payment乂 Call Girls in Dwarka Mor
 

Featured

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 

Featured (20)

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 

RSpec My Best Practice

  • 1. RS pMy e c Best Practice 13年2月3日日曜日
  • 2. make GOOD LET use of 13年2月3日日曜日
  • 3. pl e s e x a m 13年2月3日日曜日
  • 4. describe User do describe '#admin?' do s subject { user.admin? } l e context "when user is administrator" do p let(:user) do FactoryGirl.create :user, admin: true m end a it "returns true" do x expect(subject).to be_true e end end context "when user is not administrator" do let(:user) do FactoryGirl.create :user, admin: false end it "returns false" do expect(subject).to be_false end end end 13年2月3日日曜日
  • 5. describe User do describe '#admin?' do s subject { user.admin? } l e context "when user is administrator" do p let(:user) do FactoryGirl.create :user, admin: true m end a it "returns true" do x expect(subject).to be_true e end end context "when user is not administrator" do let(:user) do FactoryGirl.create :user, admin: false end it "returns false" do expect(subject).to be_false end end end 13年2月3日日曜日
  • 6. describe User do describe '#admin?' do s subject { user.admin? } l e context "when user is administrator" do NOTmDRY p let(:user) do FactoryGirl.create :user, admin: true end a it "returns true" do x expect(subject).to be_true e end end context "when user is not administrator" do let(:user) do FactoryGirl.create :user, admin: false end it "returns false" do expect(subject).to be_false end end end 13年2月3日日曜日
  • 7. Using LET for ★ Defining ★ n t e x t ★ C o 13年2月3日日曜日
  • 8. describe User do describe '#admin?' do s subject { user.admin? } l e context "when user is administrator" do p let(:user) do FactoryGirl.create :user, admin: true m end a it "returns true" do x expect(subject).to be_true e end end context "when user is not administrator" do let(:user) do FactoryGirl.create :user, admin: false end it "returns false" do expect(subject).to be_false end end end 13年2月3日日曜日
  • 9. describe User do describe '#admin?' do s subject { user.admin? } l e let(:user) { FactoryGirl.create :user, admin: admin } p context "when user is administrator" do m let(:admin) { true } a it "returns true" do x expect(subject).to be_true e end end context "when user is not administrator" do let(:admin) { false } it "returns false" do expect(subject).to be_false end end end end 13年2月3日日曜日
  • 10. describe User do describe '#admin?' do s subject { user.admin? } e context "when user is administrator" do l let(:user) { FactoryGirl.create :user, admin: admin } let(:admin) { true } p context "when user is administrator" do m let(:admin) { true } it "returnstrue" do do true" a it "returns expect(subject).to be_true x expect(subject).to be_true e end end end end context "when user is not administrator" do let(:admin) { false } it "returns false" do expect(subject).to be_false end Write ONLY changing parameters under ‘context’. end end By doing so, the spec is very clear and meaningful. end 13年2月3日日曜日
  • 11. describe User do describe '#admin?' do s subject { user.admin? } l e let(:user) { FactoryGirl.create :user, admin: admin } HOW TO p context "when user is administrator" do m let(:admin) { true } a it "returns true" do x expect(subject).to be_true e end end context "when user is not administrator" do let(:admin) { false } it "returns false" do expect(subject).to be_false end end end end 13年2月3日日曜日
  • 12. describe User do describe '#admin?' do s subject { user.admin? } l e let(:user) let(:user) { FactoryGirl.create :user, admin: }admin } { FactoryGirl.create :user, admin: admin p context "when user is administrator" do m let(:admin) { true } a it "returns true" do x expect(subject).to be_true e end end context "when user is not administrator" do let(:admin) { false } it "returns false" do ★ Prepare resources using ‘let’, ‘let!’ expect(subject).to be_false end end end and ‘before’ under describe. end 13年2月3日日曜日
  • 13. describe User do describe '#admin?' do s subject { user.admin? } l e let(:user) let(:user) { FactoryGirl.create :user, admin: }admin } { FactoryGirl.create :user, admin: admin p context "when user is administrator" do m let(:admin) { true } a it "returns true" do x expect(subject).to be_true e end end context "when user is not administrator" do let(:admin) { false } it "returns false" do expect(subject).to be_false ★ Parameters changes in context is defined by ‘let’ end end end under context, and use ONLY let at there. end 13年2月3日日曜日
  • 14. describe User do describe '#admin?' do s subject { user.admin? } l e let(:user) { FactoryGirl.create :user, admin: admin } context "when user is administrator" do p let(:admin) "when user is}administrator" do context { true } m let(:admin) { true a it "returns true" do x expect(subject).to be_true e end end context "when user is not administrator" do let(:admin) { false is not administrator" do context "when user } let(:admin) { false } it "returns false" do expect(subject).to be_false ★ Parameters changes in ‘context’ is defined by end end end ‘let’ under context, and use ONLY ‘let’ at there. end 13年2月3日日曜日
  • 15. describe User do describe '#admin?' do s subject { user.admin? } l e let(:user) { FactoryGirl.create :user, admin: admin } p MECHANISM context "when user is administrator" do m let(:admin) { true } a it "returns true" do x expect(subject).to be_true e end end context "when user is not administrator" do let(:admin) { false } it "returns false" do expect(subject).to be_false end end end end 13年2月3日日曜日
  • 16. MEC Lazy ISM HAN Evaluation http://www.fanpop.com/clubs/ho-kago-tea-time/images/29622703/title/dont-lazy-wallpaper 13年2月3日日曜日
  • 17. describe User do describe '#admin?' do s subject { user.admin? } l e let(:user) { FactoryGirl.create :user, admin: admin } p context "when user is administrator" do m let(:admin) { true } a it "returns true" do x expect(subject).to be_true e end end context "when user is not administrator" do let(:admin) { false } it "returns false" do expect(subject).to be_false end end end end 13年2月3日日曜日
  • 18. subject { user.admin? } s let(:user) do l e FactoryGirl.create :user, admin: admin p end m context "when user is administrator" do a let(:admin) { true } e x it "returns true" do expect(subject).to be_true end end 13年2月3日日曜日
  • 19. subject { user.admin? } s let(:user) do l e FactoryGirl.create :user, admin: admin p end m context "when user is administrator" do a let(:admin) { true } e x it "returns true" do expect(subject).to be_true end end ★ At first, RSpec evaluates this line. 13年2月3日日曜日
  • 20. subject { user.admin? } s let(:user) do l e FactoryGirl.create :user, admin: admin p end m context "when user is administrator" do a let(:admin) { true } e x it "returns true" do expect(subject).to be_true end end ★ Then ‘subject’ is evaluated. 13年2月3日日曜日
  • 21. subject { user.admin? } s let(:user) do l e FactoryGirl.create :user, admin: admin p end m context "when user is administrator" do a let(:admin) { true } e x it "returns true" do expect(subject).to be_true end end ★ And ‘user’ defined by ‘let’ is evaluated. 13年2月3日日曜日
  • 22. subject { user.admin? } s let(:user) do l e FactoryGirl.create :user, admin: admin p end m context "when user is administrator" do a let(:admin) { true } e x it "returns true" do expect(subject).to be_true end end ★ And ‘admin’ defined by ‘let’ is evaluated. 13年2月3日日曜日
  • 23. subject { user.admin? } s let(:user) do l e FactoryGirl.create :user, admin: admin p end FactoryGirl.create(:user, admin: true).admin? m context "when user is administrator" do a let(:admin) { true } e x it "returns true" do expect(subject).to be_true end end ★ Finally, ‘subject’ is evaluated to this. 13年2月3日日曜日
  • 24. describe User do describe '#admin?' do s subject { user.admin? } l e let(:user) { FactoryGirl.create :user, admin: admin } p context "when user is administrator" do m let(:admin) { true } a it "returns true" do x expect(subject).to be_true e end end context "when user is not administrator" do let(:admin) { false } it "returns false" do expect(subject).to be_false end end end end 13年2月3日日曜日
  • 25. Yes!! We Got Clear Spec 13年2月3日日曜日
  • 27. Using B u rd n Lazy Evaluation e on Readers... 13年2月3日日曜日
  • 28. IT’S TRADE-OFF 13年2月3日日曜日
  • 29. To make DRY SPEC use a few Lazy Evaluation 13年2月3日日曜日
  • 30. If there is many Lazy Evaluation, 13年2月3日日曜日
  • 31. IT’S TIME TO IN G T O R FA C R E and it’s a very very fun time :p 13年2月3日日曜日
  • 32. blogged at http://blog.tanaka51.jp/blog/2012/12/14/rspec-best-practice/ referenced by https://speakerdeck.com/holman http://kotas.hatenablog.jp/entry/2012/11/22/000046 13年2月3日日曜日