Module: Fix::Requirement Private

Included in:
Dsl
Defined in:
lib/fix/requirement.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Implements requirement levels as defined in RFC 2119. Provides methods for specifying different levels of requirements in test specifications: MUST, SHOULD, and MAY.

Instance Method Summary collapse

Instance Method Details

#MAY(matcher) ⇒ ::Spectus::Requirement::Optional

This method means that the item is truly optional. Implementations may include this feature if it enhances their product, and must be prepared to interoperate with implementations that include or omit this feature.

Examples:

Test optional functionality

it MAY respond_to(:cache_key)

Test optional state

it MAY be_frozen

Test optional predicates

it MAY have_attachments

Parameters:

  • matcher (#match?)

    The matcher that defines the optional condition

Returns:

  • (::Spectus::Requirement::Optional)

    An optional requirement level instance



113
114
115
# File 'lib/fix/requirement.rb', line 113

def MAY(matcher)
  ::Spectus::Requirement::Optional.new(negate: false, matcher:)
end

#MUST(matcher) ⇒ ::Spectus::Requirement::Required

This method means that the definition is an absolute requirement of the specification.

Examples:

Test exact equality

it MUST eq(42)

Test type matching

it MUST be_an_instance_of(User)

Test state changes

it MUST change(user, :status).from("pending").to("active")

Parameters:

  • matcher (#match?)

    The matcher that defines the required condition

Returns:

  • (::Spectus::Requirement::Required)

    An absolute requirement level instance



32
33
34
# File 'lib/fix/requirement.rb', line 32

def MUST(matcher)
  ::Spectus::Requirement::Required.new(negate: false, matcher:)
end

#MUST_NOT(matcher) ⇒ ::Spectus::Requirement::Required

This method means that the definition is an absolute prohibition of the specification.

Examples:

Test prohibited state

it MUST_NOT be_nil

Test prohibited type

it MUST_NOT be_a_kind_of(AdminUser)

Test prohibited exception

it MUST_NOT raise_exception(SecurityError)

Parameters:

  • matcher (#match?)

    The matcher that defines the prohibited condition

Returns:

  • (::Spectus::Requirement::Required)

    An absolute prohibition level instance



52
53
54
# File 'lib/fix/requirement.rb', line 52

def MUST_NOT(matcher)
  ::Spectus::Requirement::Required.new(negate: true, matcher:)
end

#SHOULD(matcher) ⇒ ::Spectus::Requirement::Recommended

This method means that there may exist valid reasons in particular circumstances to ignore this requirement, but the implications must be understood and carefully weighed.

Examples:

Test numeric boundaries

it SHOULD be_within(0.1).of(expected_value)

Test pattern matching

it SHOULD match(/^[A-Z][a-z]+$/)

Test custom condition

it SHOULD satisfy { |obj| obj.valid? && obj.complete? }

Parameters:

  • matcher (#match?)

    The matcher that defines the recommended condition

Returns:

  • (::Spectus::Requirement::Recommended)

    A recommended requirement level instance



73
74
75
# File 'lib/fix/requirement.rb', line 73

def SHOULD(matcher)
  ::Spectus::Requirement::Recommended.new(negate: false, matcher:)
end

#SHOULD_NOT(matcher) ⇒ ::Spectus::Requirement::Recommended

This method means that there may exist valid reasons in particular circumstances when the behavior is acceptable, but the implications should be understood and weighed carefully.

Examples:

Test state changes to avoid

it SHOULD_NOT change(object, :state)

Test predicate conditions to avoid

it SHOULD_NOT be_empty
it SHOULD_NOT have_errors

Parameters:

  • matcher (#match?)

    The matcher that defines the discouraged condition

Returns:

  • (::Spectus::Requirement::Recommended)

    A discouraged requirement level instance



92
93
94
# File 'lib/fix/requirement.rb', line 92

def SHOULD_NOT(matcher)
  ::Spectus::Requirement::Recommended.new(negate: true, matcher:)
end