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

Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...BookNet Canada
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Infrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsInfrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsYoss Cohen
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integrationmarketing932765
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxfnnc6jmgwh
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Landscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfLandscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfAarwolf Industries LLC
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Mark Simos
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Karmanjay Verma
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...itnewsafrica
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 

Recently uploaded (20)

Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Infrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsInfrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platforms
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Landscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfLandscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdf
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 

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