$ show mongoid/mongoid-rspec
Mongoid-RSpec is a Ruby gem that provides RSpec matchers for testing Mongoid documents. It offers a comprehensive set of matchers for validating associations, validations, fields, timestamps, and other Mongoid-specific features. The library is designed to work across multiple versions of Mongoid (from 3.x to 9.x) by using a compatibility layer to abstract away API differences. The code is well-organized into matcher-specific files, demonstrating good separation of concerns and handling of version-specific complexities.
The LLM identified 3 files worth highlighting for reuse:
This matcher checks the storage options of a Mongoid model (database, collection, client). It stands out for its handling of dynamic storage options defined as procs or lambdas, evaluating them in the context of the model's persistence context. The component is self-contained, reusable in other contexts requiring dynamic configuration checks, and demonstrates encapsulation of a complex concern.
This matcher verifies the existence and properties of fields in a Mongoid document (type, default value, alias, localization). It is a well-crafted, isolated component that directly interacts with the model's field definitions without unnecessary dependencies. Its thorough yet straightforward implementation makes it a safe candidate for extraction into other projects needing field introspection capabilities.
This file implements association matchers (has_many, belongs_to, etc.) while abstracting away differences between Mongoid versions (particularly the shift from 'relations' to 'associations' in Mongoid 7). It uses a base class parameterized by association type and conditionally loads the appropriate Mongoid API modules. The component demonstrates a robust strategy for maintaining compatibility across evolving dependencies.