Talks
Speakers
Events
Topics
Search
Sign in
Search
Home
Talks
Speakers
Events
Topics
Leaderboard
Use
Analytics
Sign in
search talks for
⏎
Suggest modification to this talk
Title
Description
We've all been there: you're running tests in CI and a test not related to your PR fails for seemingly no reason. Or maybe you change code and the test that should have caught it doesn't fail. From many years of experience of using Test Driven Development to write tests, fixing hundreds of non-deterministic tests, and running the Testing Guild back when I worked at Gusto, this talk will cover my top things to watch out for while testing with RSpec. https://www.wnb-rb.dev/meetups/2023/11/28
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 this talk titled "RSpec Best Practices: Toni's Top Do's and Don'ts for Writing Great Tests," Toni Rib shares insights gained from years of experience with RSpec and Test Driven Development (TDD). Rib addresses common issues in testing practices that often lead to test failures or confusion among developers. The talk emphasizes the importance of clarity and precision in writing both tests and test suites through the following key points: - **Readability**: Good tests should be easy to read and follow, ideally consisting of one assertion per test. - **Accuracy and Correct Level**: Tests should accurately reflect the behavior of the code being tested without unnecessary complications. - **Determinism**: Tests must be deterministic, meaning they consistently pass or fail without dependency on the order of test execution. - **Three A's Approach**: Following the Arrange, Act, Assert pattern helps keep tests organized and easy to understand. - **Best Practices and Common Pitfalls**: - Avoid leaving critical code paths untested and ensure tests document code behavior. - Be specific in testing expected behavior instead of using generalized assertions. - Limit the use of shared examples to avoid excessive complexity in test files. - Steer clear of asserting exact database counts and instead focus on the changes introduced by actions. - Avoid reliance on strict ordering in tests, particularly with database responses where the order of returns is not guaranteed. - Use robust data generation methods rather than relying on random data from libraries like Faker when test outcomes depend on specific values. - **Environmental Setup**: Reset environment variables in test contexts to avoid state leakage between tests. - **Documentation in Tests**: Titles in test blocks should be descriptive to aid understanding for both current and future developers. Rib also shares insights on the complexity of query planning in databases and how that impacts test consistency. Concluding, he emphasizes that tests are a critical aspect of documentation within code, serving to clarify the intended functionality of software components. By adhering to these best practices, developers can create more reliable and maintainable tests that ultimately enhance software quality and reduce flakiness in test outcomes. Rib suggests exploring additional resources for deeper understanding, including his previous talks on non-deterministic specs.
Suggest modifications
Cancel