Module: Spectus

Defined in:
lib/spectus.rb,
lib/spectus/requirement.rb,
lib/spectus/requirement/base.rb,
lib/spectus/requirement/optional.rb,
lib/spectus/requirement/required.rb,
lib/spectus/requirement/recommended.rb

Overview

Namespace for the Spectus library.

This module defines methods that can be used to qualify expectations in specifications.

Defined Under Namespace

Modules: Requirement

Class Method Summary collapse

Class Method Details

.may(matcher) ⇒ Requirement::Optional

This method mean that an item is truly optional. One vendor may choose to include the item because a particular marketplace requires it or because the vendor feels that it enhances the product while another vendor may omit the same item. An implementation which does not include a particular option must be prepared to interoperate with another implementation which does include the option, though perhaps with reduced functionality. In the same vein an implementation which does include a particular option must be prepared to interoperate with another implementation which does not include the option (except, of course, for the feature the option provides).

Examples:

An optional definition

require "spectus"
require "matchi/match"

Spectus.may Matchi::Match.new(/^foo$/)
# => #<MAY Matchi::Match(/^foo$/) negate=false>

Parameters:

  • matcher (#matches?)

    The matcher.

Returns:



104
105
106
# File 'lib/spectus.rb', line 104

def self.may(matcher)
  Requirement::Optional.new(negate: false, matcher:)
end

.must(matcher) ⇒ Requirement::Required

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

Examples:

An absolute requirement definition

require "spectus"
require "matchi/eq"

Spectus.must Matchi::Eq.new("FOO")
# => #<MUST Matchi::Eq("FOO") negate=false>

Parameters:

  • matcher (#matches?)

    The matcher.

Returns:



25
26
27
# File 'lib/spectus.rb', line 25

def self.must(matcher)
  Requirement::Required.new(negate: false, matcher:)
end

.must_not(matcher) ⇒ Requirement::Required

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

Examples:

An absolute prohibition definition

require "spectus"
require "matchi/be"

Spectus.must_not Matchi::Be.new(42)
# => #<MUST Matchi::Be(42) negate=true>

Parameters:

  • matcher (#matches?)

    The matcher.

Returns:



41
42
43
# File 'lib/spectus.rb', line 41

def self.must_not(matcher)
  Requirement::Required.new(negate: true, matcher:)
end

.should(matcher) ⇒ Requirement::Recommended

This method mean that there may exist valid reasons in particular circumstances to ignore a particular item, but the full implications must be understood and carefully weighed before choosing a different course.

Examples:

A recommended definition

require "spectus"
require "matchi/be"

Spectus.should Matchi::Be.new(true)
# => #<SHOULD Matchi::Be(true) negate=false>

Parameters:

  • matcher (#matches?)

    The matcher.

Returns:



59
60
61
# File 'lib/spectus.rb', line 59

def self.should(matcher)
  Requirement::Recommended.new(negate: false, matcher:)
end

.should_not(matcher) ⇒ Requirement::Recommended

This method mean that there may exist valid reasons in particular circumstances when the particular behavior is acceptable or even useful, but the full implications should be understood and the case carefully weighed before implementing any behavior described with this label.

Examples:

A not recommended definition

require "spectus"
require "matchi/raise_exception"

Spectus.should_not Matchi::RaiseException.new(NoMethodError)
# => #<SHOULD Matchi::RaiseException(NoMethodError) negate=true>

Parameters:

  • matcher (#matches?)

    The matcher.

Returns:



79
80
81
# File 'lib/spectus.rb', line 79

def self.should_not(matcher)
  Requirement::Recommended.new(negate: true, matcher:)
end