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

Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 

Recently uploaded (20)

Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 

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