Talks
Speakers
Events
Topics
Sign in
Home
Talks
Speakers
Events
Topics
Leaderboard
Use
Analytics
Sign in
Suggest modification to this talk
Title
Description
To mock or not mock is an important question, but let's leave it apart and admit that we, Rubyists, use mocks in our tests. Mocking is a powerful technique, but even when used responsibly, it could lead to false positives in our tests (thus, bugs leaking to production): fake objects could diverge from their real counterparts. In this talk, I'd like to discuss various approaches to keeping mocks in line with the actual implementation and present a brand new idea based on mock fixtures and contracts.
Date
Summarized using AI?
If this talk's summary was generated by AI, please check this box. A "Summarized using AI" badge will be displayed in the summary tab to indicate that the summary was generated using AI.
Show "Summarized using AI" badge on summary page
Summary
Markdown supported
In his talk "Weaving and Seaming Mocks" at RubyConf 2022, Vladimir Dementyev explores the use of mocking in Ruby testing, emphasizing the importance of keeping mocks aligned with real object behavior to avoid false positives in test results. Dementyev begins by discussing the distinction between classical and mock testing styles in Ruby. While the classical style uses real objects to mirror production code paths, the mock style replaces real dependencies with fake objects, potentially disrupting the connectivity of execution paths. This can lead to situations where tests appear successful despite real code breaks, a phenomenon referred to as false positives. Key points covered in the talk include: - The nature of mocks and their implications in testing. - Examples of how false positives can occur, such as under-refactored methods or 100% test coverage failing to indicate actual functionality. - A historical context of mocking in Ruby, including references to RSpec and the introduction of instance doubles to ensure method verification. - The significance of type checking, illustrating how type signatures can support more reliable mocking practices. - An innovative concept of using contract-based verification for mocks, where mock definitions include expected argument values and return behaviors to enhance correctness. - The introduction of a tool called "Mocksum" intended to ensure safer mocking practices by analyzing real object calls and improving type verification approaches. Throughout the talk, Dementyev uses his open-source project, Anyway Config, to provide practical examples of testing strategies, illustrating both the pitfalls of mocks and potential solutions through improved methodologies. In conclusion, the talk stresses the need for developers to be cognizant of their use of mocks, emphasizing a balance between mock and integration testing to achieve more reliable software. Key recommendations include embracing typing systems, improving mock context management, and integrating verification patterns to secure testing practices.
Suggest modifications
Cancel