---
title: "Lab: Mock Objects"
url: "https://courses.osherove.com/courses/tdd-and-bdd-in-ruby/lab-mock-objects.md"
canonical: "https://courses.osherove.com/courses/tdd-and-bdd-in-ruby/lab-mock-objects/"
tags: []
author: "Roy Osherove"
description: "Lesson 10 of 16 in TDD and BDD in Ruby (Day 3 - Advanced RSpec and Faking). Text lesson by Roy Osherove, with mocks-lab.pdf to download."
usage: "Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page)."
license: "https://creativecommons.org/licenses/by/4.0/"
---

# Lab: Mock Objects

1. [Courses](https://courses.osherove.com/#courses)
2. [TDD and BDD in Ruby](https://courses.osherove.com/courses/tdd-and-bdd-in-ruby/)
3. Day 3 - Advanced RSpec and Faking

Lesson 10 of 16

Text lesson

Please download included attachment.

## Downloads

- [mocks-lab.pdf](https://courses.osherove.com/downloads/2798/mocks-lab.pdf) (PDF, 104 KB)

## Related

- [A simple handwritten mock example](https://livebook.manning.com/book/the-art-of-unit-testing-second-edition/chapter-4#ch04lev1sec3) · The Art of Unit Testing, 2nd ed., ch. 4

    The 2nd edition's handwritten mock example; the lab's first exercise also uses only hand-written mocks, for a string calculator that notifies a slow logger.

- [Using a mock and a stub together](https://livebook.manning.com/book/the-art-of-unit-testing-second-edition/chapter-4#ch04lev1sec4) · The Art of Unit Testing, 2nd ed., ch. 4

    Section on using a mock and a stub together, as in the lab's failed-logging scenarios, where the logger raises an error and the web service must be notified.

- [Defining isolation frameworks](https://livebook.manning.com/book/the-art-of-unit-testing-third-edition/chapter-5#sigil_toc_id_99) · The Art of Unit Testing, 3rd ed., ch. 5

    Section defining isolation frameworks; the lab's later exercises repeat the work with Bogus instead of hand-written mocks.

[Previous lesson Bogus and Class Methods](https://courses.osherove.com/courses/tdd-and-bdd-in-ruby/bogus-and-class-methods/) [Next lesson Acceptance Tests with Cucumber](https://courses.osherove.com/courses/tdd-and-bdd-in-ruby/acceptance-tests-with-cucumber/)


---

## About the author

**Roy Osherove**: Senior Solutions Architect at AWS working on AI for production and AI-driven development; author of The Art of Unit Testing and Elastic Leadership, with about 20 years of consulting and training on unit testing, TDD, team leadership and continuous delivery.

### Sites

- [RobotPaper](https://robotpaper.ai/): This blog: AI patterns and anti-patterns, AI and coding agents, and engineering leadership.
- [osherove.com](https://osherove.com): Roy's personal site. Author of The Art of Unit Testing and Elastic Leadership; consulting and training on unit testing, TDD, team leadership and continuous delivery, plus about 20 years of blog posts.
- [The Art of Unit Testing](https://www.artofunittesting.com): The Art of Unit Testing, 3rd Edition (Manning): readable, maintainable, trustworthy unit tests, plus TDD workshops in C#, JavaScript, Java and Kotlin.
- [5whys.com](https://www.5whys.com): Roy's writing on software team leadership: self-organizing teams, surviving chaos, learning mode and the Elastic Leadership model.
- [Pipeline Driven](https://pipelinedriven.org): Continuous delivery and DevOps practices: build patterns, pipeline-friendly testing, DevOps metrics and enterprise DevOps.
- [Elastic Leadership](https://www.elasticleadership.com): Elastic Leadership, Roy's framework for software team leaders (survival, learning and self-organizing modes).

### Social

- X: https://x.com/royosherove
- LinkedIn: https://www.linkedin.com/in/osherove/

### Contact

- Contact form: https://forms.gle/jQSx5KoXvrVA1JCK7

### License

Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page). License: https://creativecommons.org/licenses/by/4.0/
