-
Notifications
You must be signed in to change notification settings - Fork 3
Refactor RSpec Test Kit: modular architecture with Registry DSL #303
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- Introduced comprehensive RSpec integration overview, including matchers and helpers for service validation testing. - Detailed usage examples for mocking, input/output verification, and result factories. - Provided advanced usage scenarios such as failure handling, chaining matchers, and schema validations. - Expanded with best practices, utilities, and common testing patterns for Servactory services.
- Added a new section detailing `Array` and `Hash` examples with `of:` parameters for type-specific collections. - Improved clarity on existing class usage patterns for supported data types. - Enhanced examples to aid users in understanding advanced use cases.
Complete rewrite of internal RSpec Test Kit implementation while preserving 100% DSL compatibility. All 4001 tests pass without changes. ## Architecture - Base::Submatcher - base class with Template Method pattern - Base::AttributeMatcher - unified base for Input/Internal/Output - SubmatcherRegistry - declarative DSL for submatcher registration - SubmatcherContext - value object for dependency injection - Concerns: AttributeDataAccess, ErrorMessageBuilder, ValueComparison ## Results - ~70% code reduction (HaveServiceInputMatcher: 240 → 63 lines) - Eliminated ~90% duplication between Input and Internal matchers - Adding new submatcher requires 1 line of DSL declaration - Full RSpec Matcher Protocol compliance ## Key Fixes - Ruby 3 kwargs compatibility with accepts_trailing_options flag - Proc message handling in valid_with submatcher (skip_message_check) ## Removed (legacy) - have_service_attribute_matchers/ directory (7 files) - have_service_input_matchers/ directory (4 files)
- Introduced new matcher services under `Rspec::Matchers` for extensive input, internal, output, and failure scenarios. - Added minimal, nested, and multiple input/output test examples to improve usability and clarity. - Detailed spec files, covering matcher behavior for inputs (e.g., type, required, optional, and schema validations), internals, and outputs. - Enhanced testing edge cases, such as mutual exclusivity, type validation, and custom failure messages.
- Introduced RBS signatures for all classes, modules, and methods within `Rspec::Matchers`, including base matchers (`AttributeMatcher`, `Submatcher`) and their specialized implementations (e.g., `RequiredSubmatcher`, `ValidWithSubmatcher`, `HaveServiceOutputMatcher`). - Added new RBS files to `submatchers/input`, `submatchers/shared`, and `result` directories for modular matcher hierarchy. - Defined reusable concerns (`AttributeDataAccess`, `ErrorMessageBuilder`, `ValueComparison`) for shared utilities. - Included registry and context (`SubmatcherRegistry`, `SubmatcherContext`) for parameterized submatcher construction and dependency injection. - Enhanced flow types with accurate parameter validation and class relationships for improved maintainability and Ruby 3 compatibility.
- Changed visibility of `passes?`, `build_failure_message`, and other methods from `protected` to `private` across all submatchers. - Simplified method arrangement by eliminating redundant `private` markers. - Improved code clarity and enforced stricter access control for internal methods.
- Added RBS signatures for `RSpec::Matchers` and `RSpec::Expectations` to define types for matchers, handlers, and utilities. - Introduced a new `sig/external/rspec.rbs` file for modular type definitions. - Updated `rbs_collection.lock.yaml` with new gem revisions and version adjustments for dependencies like `prism`, `rubocop-ast`, and `base64`. - Included additional signature paths in `Steepfile` for enhanced type checking. - Improved maintainability and compatibility with updated dependency configurations.
- Moved `subject` initialization to reduce duplication across specifications. - Consolidated redundant `subject` definitions via unified declarations in parent context or local scope. - Added `:aggregate_failures` metadata to improve test clarity and ensure efficient failure handling. - Reorganized multi-line expectations for improved readability and compliance with style guides. - Enhanced maintainability by ensuring a consistent structure across all spec files.
- Renamed `subject` to `submatcher` across all submatcher specs for consistency and clarity. - Applied `:aggregate_failures` metadata to tests with multiple expectations to improve readability and failure diagnosis. - Consolidated redundant `subject` redefinitions by introducing scoped aliases in nested contexts. - Streamlined multi-line expectations for cleaner formatting and better compliance with style guides.
- Reformatted submatcher definitions for better alignment and readability. - Updated method visibility and annotations to align with RuboCop settings. - Consolidated multi-line argument styles across matcher registrations. - Updated spec files to improve formatting and ensure consistency with style guides. - Enhanced method signature and argument handling for improved maintainability.
- Replaced `OpenStruct` with defined `Response` and `ResponseData` structs for better type safety and clarity. - Updated `output` definition to use the new `Response` type. - Simplified initialization of `response` to ensure stricter type compliance and improved maintainability.
- Converted `SubmatcherDefinition` and `SubmatcherContext` from `Struct` to class inheritance for better extensibility. - Added `rubocop` directive to disable `Style/StructInheritance` warning. - Improved code readability and aligned with style guides.
- Converted `SubmatcherDefinition` and `SubmatcherContext` from `Struct` inheritance to plain Ruby classes for improved extensibility and to eliminate `Style/StructInheritance` warnings. - Replaced keyword-init Struct constructor with explicit `initialize` methods for greater clarity and control over argument handling. - Updated RBS definitions with accurate type annotations and removed unused struct-related methods. - Adjusted corresponding spec files to reflect changes in initialization and removed tests related to `Struct` ancestry.
- Cleaned up an extra trailing newline for improved code consistency. - Maintained formatting alignment with style guides.
- Reformatted `attr_reader` definitions in `AttributeMatcher` to improve readability and alignment with style guides. - Added an `@attribute_type_plural` instance variable to `SubmatcherContext` with updated RBS type annotation for better clarity and extensibility.
- Reformatted `attr_reader` definitions for improved readability and adherence to style guides. - Updated multi-line method chaining in `attribute_data` for clearer structure. - Added a new `@attribute_type` declaration in the RBS file with type annotation for better type clarity and consistency.
- Reformatted `attr_reader` definitions across multiple matchers for improved readability and alignment with style guides. - Enhanced multi-line formatting for clear variable distinction and code consistency.
- Updated `attr_reader` definitions to enforce non-optional types for `class_name`, `chain_method`, `chain_aliases`, and `mutually_exclusive_with` fields. - Improved type consistency in `initialize` method by removing unnecessary nullable annotations. - Aligned type annotations with stricter RBS definitions for enhanced clarity and maintainability.
- Updated `args.pop` fallback to return an empty hash, ensuring greater safety against unexpected `nil` returns. - Adjusted the RBS definition for `resolve_submatcher_class` to use a more flexible `untyped` return type for robustness.
- Added `@attribute_target` and `@attribute_target_in` instance variables with corresponding `attr_reader` definitions. - Introduced new methods: `formatted_values`, `attribute_target`, `attribute_target_in`, and `normalize_to_array` for enhanced functionality and clarity. - Improved readability by aligning with style guides and ensuring consistent multi-line formatting.
- Added new instance variables and `attr_reader` definitions for schema, inclusion, and message submatchers, enhancing functionality and structure. - Introduced utility methods (`schema_data_equal?`, `attribute_inclusion`, `attribute_inclusion_in`, `schema_message_equal?`) to support submatcher functionality. - Improved `ValidWithSubmatcher` to support `bool` type for attributes and added a method for failure expectations. - Updated `TargetSubmatcher` for readability by renaming variables (`v` to `value`) in `formatted_values`.
- Updated `@attributes` and `attr_reader` definitions to support `Datory::Base` instead of `bool`, enhancing type consistency. - Adjusted the `initialize` method's argument type annotations accordingly. - Improved type clarity for better maintainability and extensibility of the submatcher.
- Added `# rubocop:disable Metrics/ClassLength` to bypass class length restriction as the class exceeds the preferred line count. - Ensured alignment with existing project style guidelines while maintaining functionality.
- Added usage examples for `allow_service_as_success!` with RSpec matchers. - Documented `.type()`, `.types()`, `.required`, and `.optional` matcher behavior alongside mutual exclusivity. - Expanded explanations for dynamic `.target()` usage with new `:name` parameter support. - Clarified `.message()` validation scope within validation chains. - Improved README examples and notes for better developer guidance.
- Modified `MustSubmatcher` to handle `:be_target` dynamic option in addition to `:be_inclusion`. - Updated `ValidWithSubmatcher` to include a `failure_target_passes?` method for validating the `target` dynamic option. - Suppressed RuboCop warnings for class length and method complexity where necessary. - Added spec cases to verify behavior when attributes include `:be_target` and `:be_inclusion` dynamic options.
- Reformatted multi-line lambdas in `TargetSubmatcher` for better readability and alignment with project style guides. - Updated lambdas across various matcher definitions and examples to ensure consistent formatting. - Improved clarity in dynamic option message definitions by adopting multi-line block formatting.
- Replaced `ActiveSupport::Concern` in multiple matcher concerns with `InstanceMethods` modules to improve clarity and reduce unnecessary dependency on ActiveSupport. - Updated inclusion logic for `ErrorMessageBuilder`, `ValueComparison`, and `AttributeDataAccess` by introducing explicit `self.included` methods. - Refactored methods (`build_diff_message`, `values_match?`, `attribute_data`, etc.) into instance methods for consistency and modularity. - Enhanced safety and readability in attribute data access, value formatting, and type-matching logic.
- Reordered `attr_reader` definitions across multiple submatchers for better readability and adherence to consistent formatting. - Moved private method definitions to align logically with corresponding `attr_reader` fields. - Adjusted `initialize` method placement in base validation classes to resolve misplaced positioning.
- Renamed `struct attributes` to `attributes` for better clarity and brevity in description. - Simplified test case description to improve readability.
- Updated all `to be` expectations in RSpec specs to use explicit parenthesis syntax (e.g., `.to be(true)` instead of `.to be true` and `.to be(false)` instead of `.to be false`). - Ensured consistency and improved readability across all matcher spec files (`submatchers`, `base matchers`, and `result matchers`). - Enhanced style uniformity in line with project conventions on RSpec syntax.
…ration - Removed redundant `register_submatcher :target` calls in both `HaveServiceInputMatcher` and `HaveServiceInternalMatcher` to ensure a single definition. - Rearranged submatcher definitions for improved order and readability. - Updated RBS signatures to reflect streamlined `target` submatcher integration and maintain consistency across files.
- Updated comments in `MessageSubmatcherSpec` to improve indentation consistency. - Retained explanation for skipping proc-based tests, emphasizing their coverage in integration tests where runtime context is available. - Enhanced readability and adherence to project style guidelines for inline comments.
- Refactored `input_inclusion_in` and `input_target_in` handling to support both array and non-array input types. - Used conditional logic to ensure robust value extraction for `wrong_value` generation. - Improved consistency and safeguarded against unexpected input types in `Servactory::TestKit::Utils::Faker`.
- Deleted outdated `lib/servactory/test_kit/README.md` as its content is redundant with inline documentation and other resources. - Improved repository focus by removing non-essential files. - Ensured no functional impact on existing features or tests.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.