Module: Servactory::TestKit::Rspec::Helpers::Fluent
- Included in:
- Servactory::TestKit::Rspec::Helpers
- Defined in:
- lib/servactory/test_kit/rspec/helpers/fluent.rb
Overview
Fluent API for mocking Servactory services in RSpec tests.
## Purpose
Provides modern fluent builder interface for configuring service mocks with chainable method calls. This is the recommended API for new tests.
## 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(ServiceClass)` - mock `.call` method (returns Result)
-
‘allow_service!(ServiceClass)` - mock `.call!` method (raises on failure)
## Examples
“‘ruby # Mock successful service call with outputs allow_service(PaymentService)
.succeeds(transaction_id: "txn_123", status: :completed)
# Mock with input matching allow_service(PaymentService)
.with(amount: 100)
.succeeds(transaction_id: "txn_100")
# Mock failure allow_service(PaymentService)
.fails(type: :payment_declined, message: "Card declined")
# Sequential returns allow_service(PaymentService)
.succeeds(status: :pending)
.then_succeeds(status: :completed)
“‘
Instance Method Summary collapse
-
#allow_service(service_class) ⇒ ServiceMockBuilder
Start building a service mock with fluent API for .call method.
-
#allow_service!(service_class) ⇒ ServiceMockBuilder
Start building a service mock with fluent API for .call! method.
Instance Method Details
#allow_service(service_class) ⇒ ServiceMockBuilder
Start building a service mock with fluent API for .call method.
When service fails, returns Result with ‘.error` attribute.
79 80 81 |
# File 'lib/servactory/test_kit/rspec/helpers/fluent.rb', line 79 def allow_service(service_class) Helpers::ServiceMockBuilder.new(service_class, method_type: :call, rspec_context: self) end |
#allow_service!(service_class) ⇒ ServiceMockBuilder
Start building a service mock with fluent API for .call! method.
When service fails, raises exception.
103 104 105 |
# File 'lib/servactory/test_kit/rspec/helpers/fluent.rb', line 103 def allow_service!(service_class) Helpers::ServiceMockBuilder.new(service_class, method_type: :call!, rspec_context: self) end |