SlideShare a Scribd company logo
1 of 26
Download to read offline
Mockfight!
          FlexMock vs. Mocha
          Patrick Reagan
          patrick@viget.com
          Director, Application Development




Viget Labs
we build web business



July 18, 2007                 © Copyright 2007 Viget Labs, LLC – www.viget.com
Mockfight! FlexMock vs. Mocha                                                      2




What are Mocks?


          “Mock objects are simulated
          objects that mimic the behavior of
          real objects in controlled ways”
                          - Wikipedia


Viget Labs
we build web business



July 18, 2007                   © Copyright 2007 Viget Labs, LLC – www.viget.com
Mockfight! FlexMock vs. Mocha                                                      3




When to Mock?

Use mocks when you want to:

• Control the behavior of internal method calls

• Remove dependence on external systems

• Improve test performance



Viget Labs
we build web business



July 18, 2007                   © Copyright 2007 Viget Labs, LLC – www.viget.com
Mockfight! FlexMock vs. Mocha                                                      4




Control Behavior

What does this return?




Need to maintain consistency between calls

Viget Labs
we build web business



July 18, 2007                   © Copyright 2007 Viget Labs, LLC – www.viget.com
Mockfight! FlexMock vs. Mocha                                                                      5




Control Behavior

How do we test?


                                                                                   Magic happens
                                                                                   here




Stub the call to Die#rand (using Mocha)


Viget Labs
we build web business



July 18, 2007                   © Copyright 2007 Viget Labs, LLC – www.viget.com
Mockfight! FlexMock vs. Mocha                                                      6




Remove Dependencies

Example: retrieve response data via HTTP




To test this, we need to mock:
 • Call to URI#parse
 • Calls to Net::HTTP#new and Net::HTTP#head


Viget Labs
we build web business



July 18, 2007                   © Copyright 2007 Viget Labs, LLC – www.viget.com
Mockfight! FlexMock vs. Mocha                                                      7




Mockfight!

Expanded example:
• Create class method to check for resource
• Handle errors and redirects
• Iteratively develop functionality while testing
• Examine the differences between libraries



Viget Labs
we build web business



July 18, 2007                   © Copyright 2007 Viget Labs, LLC – www.viget.com
Mockfight! FlexMock vs. Mocha                                                      8




Round 1

Test scenario when URI#parse raises exception




Viget Labs
we build web business



July 18, 2007                   © Copyright 2007 Viget Labs, LLC – www.viget.com
Mockfight! FlexMock vs. Mocha                                                      9




Round 1: Results

FlexMock




Mocha




Viget Labs
we build web business



July 18, 2007                   © Copyright 2007 Viget Labs, LLC – www.viget.com
Mockfight! FlexMock vs. Mocha                                                      10




Round 2

Check for a valid response




Viget Labs
we build web business



July 18, 2007                   © Copyright 2007 Viget Labs, LLC – www.viget.com
Mockfight! FlexMock vs. Mocha                                                      11




Round 2: Results

FlexMock




Mocha




Viget Labs
we build web business



July 18, 2007                   © Copyright 2007 Viget Labs, LLC – www.viget.com
Mockfight! FlexMock vs. Mocha                                                      12




Round 3

Check for response type instead of status code




* Our previous tests for response status code are now invalid


Viget Labs
we build web business



July 18, 2007                   © Copyright 2007 Viget Labs, LLC – www.viget.com
Mockfight! FlexMock vs. Mocha                                                      13




Round 3: Results

FlexMock




Mocha




Viget Labs
we build web business



July 18, 2007                   © Copyright 2007 Viget Labs, LLC – www.viget.com
Mockfight! FlexMock vs. Mocha                                                      14




Round 4

Follow an HTTP redirect response




Viget Labs
we build web business



July 18, 2007                   © Copyright 2007 Viget Labs, LLC – www.viget.com
Mockfight! FlexMock vs. Mocha                                                      15




Round 4: Results

FlexMock




Viget Labs
we build web business



July 18, 2007                   © Copyright 2007 Viget Labs, LLC – www.viget.com
Mockfight! FlexMock vs. Mocha                                                      16




Round 4: Results

Mocha




Viget Labs
we build web business



July 18, 2007                   © Copyright 2007 Viget Labs, LLC – www.viget.com
Mockfight! FlexMock vs. Mocha                                                      17




Round 5

Handling maximum number of redirects




Viget Labs
we build web business



July 18, 2007                   © Copyright 2007 Viget Labs, LLC – www.viget.com
Mockfight! FlexMock vs. Mocha                                                      18




Round 5: Results

FlexMock




Viget Labs
we build web business



July 18, 2007                   © Copyright 2007 Viget Labs, LLC – www.viget.com
Mockfight! FlexMock vs. Mocha                                                      19




Round 5: Results

Mocha




Viget Labs
we build web business



July 18, 2007                   © Copyright 2007 Viget Labs, LLC – www.viget.com
Mockfight! FlexMock vs. Mocha                                                      20




Bonus Round

Mocking ActiveRecord#find in controllers




Viget Labs
we build web business



July 18, 2007                   © Copyright 2007 Viget Labs, LLC – www.viget.com
Mockfight! FlexMock vs. Mocha                                                      21




Bonus Round: Results

FlexMock




Mocha




Viget Labs
we build web business



July 18, 2007                   © Copyright 2007 Viget Labs, LLC – www.viget.com
Mockfight! FlexMock vs. Mocha                                                      22




But Wait, There’s More

Mocha has parameter matchers (in SVN)
You can write code like this:




Viget Labs
we build web business



July 18, 2007                   © Copyright 2007 Viget Labs, LLC – www.viget.com
Mockfight! FlexMock vs. Mocha                                                      23




Conclusion


• Newest versions of gems contain similar features

• FlexMock can accept blocks for further mocking

• Personal preference of syntax is the deciding factor



Viget Labs
we build web business



July 18, 2007                   © Copyright 2007 Viget Labs, LLC – www.viget.com
Mockfight! FlexMock vs. Mocha                                                         24




It’s a Tie!




                                Ultimately, two great libraries - just pick one

Viget Labs
we build web business



July 18, 2007                      © Copyright 2007 Viget Labs, LLC – www.viget.com
Mockfight! FlexMock vs. Mocha                                                      25




Questions?




                                                            ? ?    ?
Viget Labs
we build web business



July 18, 2007                   © Copyright 2007 Viget Labs, LLC – www.viget.com
Mockfight! FlexMock vs. Mocha                                                      26




Additional Information

FlexMock (Jim Weirich)
          http://www.onestepback.org/software/flexmock


Mocha (James Mead)
          http://mocha.rubyforge.org


                         http://www.slideshare.net/viget
Viget Labs
we build web business



July 18, 2007                   © Copyright 2007 Viget Labs, LLC – www.viget.com

More Related Content

Recently uploaded

New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsPrecisely
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsAndrey Dotsenko
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfngoud9212
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 

Recently uploaded (20)

New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power Systems
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdf
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
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
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
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...
 

Mockfight! FlexMock vs. Mocha

  • 1. Mockfight! FlexMock vs. Mocha Patrick Reagan patrick@viget.com Director, Application Development Viget Labs we build web business July 18, 2007 © Copyright 2007 Viget Labs, LLC – www.viget.com
  • 2. Mockfight! FlexMock vs. Mocha 2 What are Mocks? “Mock objects are simulated objects that mimic the behavior of real objects in controlled ways” - Wikipedia Viget Labs we build web business July 18, 2007 © Copyright 2007 Viget Labs, LLC – www.viget.com
  • 3. Mockfight! FlexMock vs. Mocha 3 When to Mock? Use mocks when you want to: • Control the behavior of internal method calls • Remove dependence on external systems • Improve test performance Viget Labs we build web business July 18, 2007 © Copyright 2007 Viget Labs, LLC – www.viget.com
  • 4. Mockfight! FlexMock vs. Mocha 4 Control Behavior What does this return? Need to maintain consistency between calls Viget Labs we build web business July 18, 2007 © Copyright 2007 Viget Labs, LLC – www.viget.com
  • 5. Mockfight! FlexMock vs. Mocha 5 Control Behavior How do we test? Magic happens here Stub the call to Die#rand (using Mocha) Viget Labs we build web business July 18, 2007 © Copyright 2007 Viget Labs, LLC – www.viget.com
  • 6. Mockfight! FlexMock vs. Mocha 6 Remove Dependencies Example: retrieve response data via HTTP To test this, we need to mock: • Call to URI#parse • Calls to Net::HTTP#new and Net::HTTP#head Viget Labs we build web business July 18, 2007 © Copyright 2007 Viget Labs, LLC – www.viget.com
  • 7. Mockfight! FlexMock vs. Mocha 7 Mockfight! Expanded example: • Create class method to check for resource • Handle errors and redirects • Iteratively develop functionality while testing • Examine the differences between libraries Viget Labs we build web business July 18, 2007 © Copyright 2007 Viget Labs, LLC – www.viget.com
  • 8. Mockfight! FlexMock vs. Mocha 8 Round 1 Test scenario when URI#parse raises exception Viget Labs we build web business July 18, 2007 © Copyright 2007 Viget Labs, LLC – www.viget.com
  • 9. Mockfight! FlexMock vs. Mocha 9 Round 1: Results FlexMock Mocha Viget Labs we build web business July 18, 2007 © Copyright 2007 Viget Labs, LLC – www.viget.com
  • 10. Mockfight! FlexMock vs. Mocha 10 Round 2 Check for a valid response Viget Labs we build web business July 18, 2007 © Copyright 2007 Viget Labs, LLC – www.viget.com
  • 11. Mockfight! FlexMock vs. Mocha 11 Round 2: Results FlexMock Mocha Viget Labs we build web business July 18, 2007 © Copyright 2007 Viget Labs, LLC – www.viget.com
  • 12. Mockfight! FlexMock vs. Mocha 12 Round 3 Check for response type instead of status code * Our previous tests for response status code are now invalid Viget Labs we build web business July 18, 2007 © Copyright 2007 Viget Labs, LLC – www.viget.com
  • 13. Mockfight! FlexMock vs. Mocha 13 Round 3: Results FlexMock Mocha Viget Labs we build web business July 18, 2007 © Copyright 2007 Viget Labs, LLC – www.viget.com
  • 14. Mockfight! FlexMock vs. Mocha 14 Round 4 Follow an HTTP redirect response Viget Labs we build web business July 18, 2007 © Copyright 2007 Viget Labs, LLC – www.viget.com
  • 15. Mockfight! FlexMock vs. Mocha 15 Round 4: Results FlexMock Viget Labs we build web business July 18, 2007 © Copyright 2007 Viget Labs, LLC – www.viget.com
  • 16. Mockfight! FlexMock vs. Mocha 16 Round 4: Results Mocha Viget Labs we build web business July 18, 2007 © Copyright 2007 Viget Labs, LLC – www.viget.com
  • 17. Mockfight! FlexMock vs. Mocha 17 Round 5 Handling maximum number of redirects Viget Labs we build web business July 18, 2007 © Copyright 2007 Viget Labs, LLC – www.viget.com
  • 18. Mockfight! FlexMock vs. Mocha 18 Round 5: Results FlexMock Viget Labs we build web business July 18, 2007 © Copyright 2007 Viget Labs, LLC – www.viget.com
  • 19. Mockfight! FlexMock vs. Mocha 19 Round 5: Results Mocha Viget Labs we build web business July 18, 2007 © Copyright 2007 Viget Labs, LLC – www.viget.com
  • 20. Mockfight! FlexMock vs. Mocha 20 Bonus Round Mocking ActiveRecord#find in controllers Viget Labs we build web business July 18, 2007 © Copyright 2007 Viget Labs, LLC – www.viget.com
  • 21. Mockfight! FlexMock vs. Mocha 21 Bonus Round: Results FlexMock Mocha Viget Labs we build web business July 18, 2007 © Copyright 2007 Viget Labs, LLC – www.viget.com
  • 22. Mockfight! FlexMock vs. Mocha 22 But Wait, There’s More Mocha has parameter matchers (in SVN) You can write code like this: Viget Labs we build web business July 18, 2007 © Copyright 2007 Viget Labs, LLC – www.viget.com
  • 23. Mockfight! FlexMock vs. Mocha 23 Conclusion • Newest versions of gems contain similar features • FlexMock can accept blocks for further mocking • Personal preference of syntax is the deciding factor Viget Labs we build web business July 18, 2007 © Copyright 2007 Viget Labs, LLC – www.viget.com
  • 24. Mockfight! FlexMock vs. Mocha 24 It’s a Tie! Ultimately, two great libraries - just pick one Viget Labs we build web business July 18, 2007 © Copyright 2007 Viget Labs, LLC – www.viget.com
  • 25. Mockfight! FlexMock vs. Mocha 25 Questions? ? ? ? Viget Labs we build web business July 18, 2007 © Copyright 2007 Viget Labs, LLC – www.viget.com
  • 26. Mockfight! FlexMock vs. Mocha 26 Additional Information FlexMock (Jim Weirich) http://www.onestepback.org/software/flexmock Mocha (James Mead) http://mocha.rubyforge.org http://www.slideshare.net/viget Viget Labs we build web business July 18, 2007 © Copyright 2007 Viget Labs, LLC – www.viget.com