-
Notifications
You must be signed in to change notification settings - Fork 3
Refactor RSpec test kit: Implement fluent service mocking API with improved exception handling #304
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 `Servactory::TestKit::Rspec::Helpers`, including fluent mocks, sequential returns, and argument matchers for seamless service testing. - Added support for success and failure service mocks with flexible argument patterns. - Implemented output validation, result matchers, and enhanced error handling. - Included helper modules, such as `ServiceExpectationBuilder`, `MockExecutor`, `OutputValidator`, and `ServiceMockBuilder`, to improve RSpec test writing. - Provided comprehensive examples in a dedicated `README` for usage guidance, covering fluent API mocks, validation, and call behavior. - Created sample services and RSpec specs (e.g., `Example1` and `Example2`) illustrating real-world use cases.
- Renamed `cfg` to `config` in the `all_returns?` method to improve readability and maintain consistency with naming conventions across the codebase. - No changes to functionality or behavior.
- Removed `ServiceExpectationBuilder` to streamline code and focus on `ServiceMockBuilder` for mocking service behaviors. - Introduced `allow_service!` for mocking `call!` method behavior, aligning with `allow_service` for `call` method. - Enhanced `MockExecutor` with validation for failure exceptions, ensuring proper exception types are set. - Improved error messages with clearer guidance on configuring failures and exceptions. - Updated RSpec helpers to reflect the simplified API and removed redundant methods.
- Deferred mock execution in `as_failure` and `for_failure` to wait for `with_exception`, ensuring correct exception validation. - Adjusted `with_exception` to execute the appropriate mock method based on configurations and execution state. - Added comments clarifying the behavior changes for better maintainability and readability. - Improved sequence handling for failure mocks with exceptions.
- Replaced `mock_service` examples with `allow_service` in test specs for better alignment with the new service mocking approach. - Created `AllowServiceFluentApi` examples (`Example1` through `Example5`) to illustrate the updated API, replacing now-obsolete `MockServiceFluentApi` examples. - Updated associated RSpec tests to demonstrate the `allow_service` API, including success, failure, and sequential returns scenarios. - Removed deprecated `MockServiceFluentApi` examples and their test cases for consistency and to streamline codebase.
- Removed `type` parameter from `fail!` calls to simplify failure handling logic in `Example1Child`. Only `message` is now required. - Updated examples and RSpec tests to replace `:payment_error` and other specific error types with `:base` for a unified error type. - Adjusted failure-related code snippets in README and helper files to reflect the updated exception type. - Deleted outdated validation tests for `as_failure` without allowing exceptions, improving overall test suite clarity.
- Updated `example1_spec` to transition from result verification to exception raising, aligning with the fluent API's failure-handling changes. - Enhanced error message helper with full exception signature examples for clarity. - Refined method signature documentation to include `meta` parameter for comprehensive guidance.
- Updated test cases across `result_spec`, `example1_spec`, and `example3_spec` to include `meta` expectation validation. - Ensured failure exceptions verify that `meta` is `nil`, improving test coverage and clarity. - Aligned the tests with the refined exception structure for consistency.
- Added core helpers for fluent service mocking, including `ServiceMockBuilder`, `MockExecutor`, `OutputValidator`, `ServiceMockConfig`, and various concerns for error messages and validations. - Introduced methods for success, failure, and sequential mocks, compatible with both fluent and legacy APIs. - Enhanced mocking with argument matchers, output validation, and exception handling for robust test coverage. - Updated RSpec helpers to reflect the new fluent API while maintaining legacy API compatibility.
- Applied inline conditional expressions in `Example1` and `Example5` to simplify failure and success logic. - Added `rubocop:disable` comments for long methods and classes (`# rubocop:disable Metrics/MethodLength`, `# rubocop:disable Metrics/ClassLength`, `# rubocop:disable Metrics/AbcSize`) to maintain compliance with code metrics. - Standardized the usage of single quotes in strings for error messages across helpers. - Removed an unnecessary blank line in `example4_spec.rb` for cleaner formatting.
- Added detailed documentation to RSpec matchers, including `OptionalSubmatcher`, `DefaultSubmatcher`, `BeFailureServiceMatcher`, and `BeSuccessServiceMatcher`, for clearer usage and purpose explanation. - Enhanced `Faker` utilities with comprehensive examples of supported types and usage scenarios. - Documented the `Result` factory, `FakeType` class, and `ErrorMessageBuilder` helper with usage, purpose, and method descriptions to improve readability and maintainability. - Updated all methods with parameter and return annotations for clarity and consistency.
- Implemented `AllowServiceAsFailureBang::Example2` and `AllowServiceAsSuccess::Example4`, showcasing parent and child service interactions with failure and success behaviors respectively. - Added `AllowServiceFluentApi` examples (`example6` through `example9`), illustrating use cases including failure scenarios, sequential returns, and multiple outputs in parent-child service structures. - Created test cases for all new examples, demonstrating the usage of `allow_service` and `allow_service!` with input/output matchers, validations, and exception handling. - Refactored `example5_spec` to improve clarity, transitioning from argument matchers to input matchers for consistency with recent updates.
- Replaced `as_success` and `as_failure` with `succeeds` and `fails`, simplifying the service mocking fluent API. - Unified success and failure mock configurations into single methods that combine result type and output/exception setup for increased readability and conciseness. - Updated test examples (`examples1_spec` through `examples9_spec`) to use the new `succeeds` and `fails` methods. - Enhanced documentation in `ServiceMockBuilder` and RSpec helpers to reflect the updated API, including sequential mock usage. - Improved input/output validation logic and organized helper code for better maintainability.
- Introduced `InputValidator` to ensure mock input arguments match service input definitions. Automatically validates inputs when `.with()` is called. - Added support for multiple matcher types (`Hash`, `including`, `no_inputs`, `any_inputs`, and `excluding`) to enhance flexibility in input validation. - Updated `ServiceMockBuilder` to replace `.inputs()` with `.with()` for input matching, deprecating the former method. - Enhanced input validation error handling with detailed messages for unknown or missing inputs. - Adjusted related test cases to validate the behavior of input validation and updated existing `.inputs()` examples to use `.with()`. - Modified documentation to reflect the addition of `InputValidator` and the new `.with()` method as the recommended approach for input mocking.
- Deprecated `.inputs()` method replaced with `.with()` for all input matching cases in test specs (`example5_spec`, `example7_spec`, `example8_spec`). - Updated `ServiceMockBuilder` to fully remove `.inputs()` alias and associated deprecation notes. - Adjusted documentation and examples to use `.with()` as the standard approach for input mocking. - Improved inline examples in RSpec helpers and documentation for clarity, promoting the recommended fluent API. - Enhanced error messages and validations to align with the updated method.
- Replaced `ExceptionClass` with `MyException` in error message examples to improve clarity and maintain consistency with updated service mocking conventions. - Ensured the inline documentation reflects the recommended exception setup.
- Added RuboCop disables (`Metrics/AbcSize`, `Metrics/PerceivedComplexity`, and `Metrics/CyclomaticComplexity`) for the `process_with_retries` method. - Ensures compliance with coding standards without altering method logic.
- Added support for `Datory::Base` as valid input type for `expect_failure_with!` method, enhancing flexibility in mock input definitions. - Introduced `failure_target_passes?` method for refined error handling and validation. - Retained backward compatibility while extending input matching capabilities.
- Updated the parameter order of `fails` and `then_fails` in `ServiceMockBuilder` to place `type` before `message`, ensuring consistency across the API. - Refactored RBS signatures, RSpec helpers, and inline documentation examples to match the updated parameter order. - Adjusted README and test documentation to reflect the change. - Improved overall readability and alignment with the fluent API conventions.
- Added `rubocop:disable Style/KeywordParametersOrder` comments to `fails` and `then_fails` methods in `ServiceMockBuilder` to suppress warnings about keyword parameter order. - Ensured no functional changes were introduced, maintaining the current behavior and passing tests.
- Introduced `Helpers::Fluent` for a modern, chainable API aimed at simplifying service mocking. Features methods like `allow_service` and `allow_service!` focused on fluent syntax. - Added `Helpers::Legacy` for backward compatibility with older testing approaches, retaining methods like `allow_service_as_success` and `allow_service_as_failure`. - Updated `Helpers` module to include both Fluent and Legacy APIs, facilitating a smoother transition to the newer interface while maintaining support for legacy tests. - Refactored method definitions, inline documentation, and RBS type signatures to align with this modular approach. - Prepared for future extensions and enhancements in service mocking capabilities through this clear separation.
- Deleted the TestKit documentation, which included detailed examples for mocking services, input matchers, result matchers, and service verification. - Removed sections describing Fluent and Legacy APIs, sequential returns, and automatic validation to streamline the repository. - This cleanup prepares the codebase for a more focused documentation approach while reducing redundancy.
- Introduced `Servactory::TestKit::Utils::Faker` module to provide a centralized utility for generating fake data types like `Symbol`, `String`, `Integer`, `Float`, `Range`, `Array`, and `Hash`. - Added private methods to generate fake data for various classes, enhancing test flexibility. - Included support for custom symbol-based collections and error handling for unsupported faker types. - Improved modularity and reusability for test data generation in `TestKit`.
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.