Class: Servactory::TestKit::Rspec::Matchers::Submatchers::Input::RequiredSubmatcher

Inherits:
Base::Submatcher
  • Object
show all
Defined in:
lib/servactory/test_kit/rspec/matchers/submatchers/input/required_submatcher.rb

Overview

Submatcher for validating that an input is required.

## Purpose

Validates that a service input has ‘required: true` option set. Optionally validates a custom error message for the required validation.

## Usage

“‘ruby it { is_expected.to have_service_input(:user_id).required } it { is_expected.to have_service_input(:name).required(“Name is mandatory”) } “`

## Validation

Checks the ‘:required` option in attribute data where `is: true`. If a custom message is provided, also validates the message matches.

Instance Attribute Summary

Attributes inherited from Base::Submatcher

#missing_option

Instance Method Summary collapse

Methods inherited from Base::Submatcher

#failure_message, #failure_message_when_negated, #matches?

Methods included from Concerns::ValueComparison

included

Methods included from Concerns::ErrorMessageBuilder

included

Methods included from Concerns::AttributeDataAccess

included

Constructor Details

#initialize(context, custom_message = nil) ⇒ RequiredSubmatcher

Creates a new required submatcher.

Parameters:

  • context (Base::SubmatcherContext)

    The submatcher context

  • custom_message (String, nil) (defaults to: nil)

    Optional expected error message



33
34
35
36
# File 'lib/servactory/test_kit/rspec/matchers/submatchers/input/required_submatcher.rb', line 33

def initialize(context, custom_message = nil)
  super(context)
  @custom_message = custom_message
end

Instance Method Details

#descriptionString

Returns description for RSpec output.

Returns:

  • (String)

    Human-readable description



41
42
43
# File 'lib/servactory/test_kit/rspec/matchers/submatchers/input/required_submatcher.rb', line 41

def description
  "required: true"
end