Module: Servactory::TestKit::Rspec::Helpers::Legacy
- Included in:
- Servactory::TestKit::Rspec::Helpers
- Defined in:
- lib/servactory/test_kit/rspec/helpers/legacy.rb
Overview
Backward-compatible API for mocking Servactory services in RSpec tests.
## Purpose
Provides legacy helper methods for mocking Servactory service calls. These methods are maintained for backward compatibility with existing tests. For new tests, consider using the fluent API via Fluent module.
## Usage
Include in RSpec configuration via the main Helpers module:
“‘ruby RSpec.configure do |config|
config.include Servactory::TestKit::Rspec::Helpers, type: :service
end “‘
## Available Methods
-
‘allow_service_as_success!` - mock `.call!` method for success
-
‘allow_service_as_success` - mock `.call` method for success
-
‘allow_service_as_failure!` - mock `.call!` method for failure
-
‘allow_service_as_failure` - mock `.call` method for failure
## Examples
“‘ruby # Mock call method (returns Result) allow_service_as_success(PaymentService) do
{ transaction_id: "txn_123" }
end
# Mock call! method (raises on failure) allow_service_as_success!(PaymentService, with: { amount: 100 }) do
{ transaction_id: "txn_123" }
end
# Mock failure allow_service_as_failure(PaymentService) do
{
exception: ApplicationService::Exceptions::Failure.new(
type: :base,
message: "Failed"
)
}
end “‘
Instance Method Summary collapse
-
#allow_service_as_failure(service_class, with: nil) { ... } ⇒ void
Mock the ‘call` method to return a failure result.
-
#allow_service_as_failure!(service_class, with: nil) { ... } ⇒ void
Mock the ‘call!` method to raise a failure exception.
-
#allow_service_as_success(service_class, with: nil) { ... } ⇒ void
Mock the ‘call` method to return a successful result.
-
#allow_service_as_success!(service_class, with: nil) { ... } ⇒ void
Mock the ‘call!` method to return a successful result.
Instance Method Details
#allow_service_as_failure(service_class, with: nil) { ... } ⇒ void
This method returns an undefined value.
Mock the ‘call` method to return a failure result.
131 132 133 |
# File 'lib/servactory/test_kit/rspec/helpers/legacy.rb', line 131 def allow_service_as_failure(service_class, with: nil, &block) allow_service_legacy(service_class, :as_failure, with:, &block) end |
#allow_service_as_failure!(service_class, with: nil) { ... } ⇒ void
This method returns an undefined value.
Mock the ‘call!` method to raise a failure exception.
110 111 112 |
# File 'lib/servactory/test_kit/rspec/helpers/legacy.rb', line 110 def allow_service_as_failure!(service_class, with: nil, &block) allow_service_legacy!(service_class, :as_failure, with:, &block) end |
#allow_service_as_success(service_class, with: nil) { ... } ⇒ void
This method returns an undefined value.
Mock the ‘call` method to return a successful result.
91 92 93 |
# File 'lib/servactory/test_kit/rspec/helpers/legacy.rb', line 91 def allow_service_as_success(service_class, with: nil, &block) allow_service_legacy(service_class, :as_success, with:, &block) end |
#allow_service_as_success!(service_class, with: nil) { ... } ⇒ void
This method returns an undefined value.
Mock the ‘call!` method to return a successful result.
75 76 77 |
# File 'lib/servactory/test_kit/rspec/helpers/legacy.rb', line 75 def allow_service_as_success!(service_class, with: nil, &block) allow_service_legacy!(service_class, :as_success, with:, &block) end |