RSpec Shared Examples: A Task Guide for DRYing Interface Contracts
Learn how to define RSpec shared examples once and reuse them across classes that implement the same interface, with parameterization, file organization, and debugging tips.
ReadMeFeed / Community knowledge
Real questions. Useful conversations. Find the people who know your stack.
Learn how to define RSpec shared examples once and reuse them across classes that implement the same interface, with parameterization, file organization, and debugging tips.
Use RSpec verifying doubles to catch stale mocks early. Compare instance_double, class_double, and object_double with validation steps.
Learn how to use RSpec’s tag filtering to run specific tests, skip slow ones, and focus on critical scenarios. The article covers inline tags, derived metadata, focused execution, and best‑practice trade‑offs.
Learn how to eliminate duplicated expectations in RSpec by using shared examples with parameters, see a concrete Money/Weight example, and understand the trade‑offs.
Replace hidden instance-variable dependencies in RSpec before hooks with let and let!. Make setup explicit, lazy where possible, and isolated so failures point to the example.
Choose wisely between RSpec’s <code>let</code> and <code>let!</code> to control when data is created. This guide explains lazy vs eager evaluation, shows a real example, and lists trade‑offs so your tests stay fast and reliable.
Learn how to define shared_examples in RSpec, parameterize them with block arguments, and apply the same behavior to different object types while keeping your test suite DRY and readable.
Learn how to configure RubyMine's RSpec runner to move from terminal-based testing to integrated debugging, including Gemfile requirements and common pitfalls like Spring stale state.
Stop fighting leaky test databases. Learn how to use RSpec's around(:each) hook to wrap tests in transactions for faster, cleaner, and more reliable Rails test suites.