Module: Servactory::TestKit::Rspec::Helpers::ArgumentMatchers

Included in:
Servactory::TestKit::Rspec::Helpers
Defined in:
lib/servactory/test_kit/rspec/helpers/argument_matchers.rb

Overview

RSpec argument matchers with service-friendly aliases.

## Purpose

Provides semantic aliases for RSpec’s argument matchers that read more naturally in service testing contexts.

## Usage

**Fluent API:**

“‘ruby allow_service(Service).with(including(amount: 100)).succeeds(result: “ok”) allow_service(Service).with(excluding(secret: anything)).succeeds(result: “ok”) allow_service(Service).with(any_inputs).succeeds(result: “ok”) allow_service(EmptyService).with(no_inputs).succeeds(result: “ok”) “`

**Legacy API:**

“‘ruby allow_service_as_success!(Service, with: including(amount: 100)) { { result: “ok” } } allow_service_as_success!(Service, with: excluding(secret: anything)) { { result: “ok” } } allow_service_as_success!(Service, with: any_inputs) { { result: “ok” } } allow_service_as_success!(EmptyService, with: no_inputs) { { result: “ok” } } “`

Instance Method Summary collapse

Instance Method Details

#any_inputsRSpec::Mocks::ArgumentMatchers::AnyArgMatcher

Matches any service inputs (wildcard matcher).

Useful for “don’t care” scenarios where input values don’t matter.

Examples:

Fluent API

allow_service(Service).with(any_inputs).succeeds(result: "ok")

Legacy API

allow_service_as_success!(Service, with: any_inputs) { { result: "ok" } }

Returns:

  • (RSpec::Mocks::ArgumentMatchers::AnyArgMatcher)


77
78
79
# File 'lib/servactory/test_kit/rspec/helpers/argument_matchers.rb', line 77

def any_inputs
  anything
end

#excluding(hash) ⇒ RSpec::Mocks::ArgumentMatchers::HashExcludingMatcher

Matches a hash NOT containing specified key-value pairs.

Alias for RSpec’s ‘hash_excluding` with service-friendly naming.

Examples:

Fluent API

allow_service(Service).with(excluding(secret: anything)).succeeds(result: "ok")

Legacy API

allow_service_as_success!(Service, with: excluding(secret: anything)) { { result: "ok" } }

Parameters:

  • hash (Hash)

    Key-value pairs to exclude

Returns:

  • (RSpec::Mocks::ArgumentMatchers::HashExcludingMatcher)


62
63
64
# File 'lib/servactory/test_kit/rspec/helpers/argument_matchers.rb', line 62

def excluding(hash)
  hash_excluding(hash)
end

#including(hash) ⇒ RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher

Matches a hash containing specified key-value pairs.

Alias for RSpec’s ‘hash_including` with service-friendly naming.

Examples:

Fluent API

allow_service(Service).with(including(amount: 100)).succeeds(result: "ok")

Legacy API

allow_service_as_success!(Service, with: including(amount: 100)) { { result: "ok" } }

Parameters:

  • hash (Hash)

    Expected key-value pairs

Returns:

  • (RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher)


46
47
48
# File 'lib/servactory/test_kit/rspec/helpers/argument_matchers.rb', line 46

def including(hash)
  hash_including(hash)
end

#no_inputsRSpec::Mocks::ArgumentMatchers::NoArgsMatcher

Matches no arguments (for services without inputs).

Examples:

Fluent API

allow_service(EmptyService).with(no_inputs).succeeds(result: "ok")

Legacy API

allow_service_as_success!(EmptyService, with: no_inputs) { { result: "ok" } }

Returns:

  • (RSpec::Mocks::ArgumentMatchers::NoArgsMatcher)


90
91
92
# File 'lib/servactory/test_kit/rspec/helpers/argument_matchers.rb', line 90

def no_inputs
  no_args
end