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$/) isolate=false negate=false>

Parameters:

  • matcher (#matches?)

    The matcher.

Returns:



184
185
186
187
188
189
190
# File 'lib/spectus.rb', line 184

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

.may!(matcher) ⇒ Object

Examples:

An optional definition with isolation

require "spectus"
require "matchi/match"

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

See Also:



200
201
202
203
204
205
206
# File 'lib/spectus.rb', line 200

def self.may!(matcher)
  Requirement::Optional.new(
    isolate: true,
    negate:  false,
    matcher: 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") isolate=false negate=false>

Parameters:

  • matcher (#matches?)

    The matcher.

Returns:



25
26
27
28
29
30
31
# File 'lib/spectus.rb', line 25

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

.must!(matcher) ⇒ Object

Examples:

An absolute requirement definition with isolation

require "spectus"
require "matchi/eq"

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

See Also:



41
42
43
44
45
46
47
# File 'lib/spectus.rb', line 41

def self.must!(matcher)
  Requirement::Required.new(
    isolate: true,
    negate:  false,
    matcher: 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) isolate=false negate=true>

Parameters:

  • matcher (#matches?)

    The matcher.

Returns:



61
62
63
64
65
66
67
# File 'lib/spectus.rb', line 61

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

.must_not!(matcher) ⇒ Object

Examples:

An absolute prohibition definition with isolation

require "spectus"
require "matchi/be"

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

See Also:



77
78
79
80
81
82
83
# File 'lib/spectus.rb', line 77

def self.must_not!(matcher)
  Requirement::Required.new(
    isolate: true,
    negate:  true,
    matcher: 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) isolate=false negate=false>

Parameters:

  • matcher (#matches?)

    The matcher.

Returns:



99
100
101
102
103
104
105
# File 'lib/spectus.rb', line 99

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

.should!(matcher) ⇒ Object

Examples:

A recommended definition with isolation

require "spectus"
require "matchi/be"

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

See Also:



115
116
117
118
119
120
121
# File 'lib/spectus.rb', line 115

def self.should!(matcher)
  Requirement::Recommended.new(
    isolate: true,
    negate:  false,
    matcher: 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) isolate=false negate=true>

Parameters:

  • matcher (#matches?)

    The matcher.

Returns:



139
140
141
142
143
144
145
# File 'lib/spectus.rb', line 139

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

.should_not!(matcher) ⇒ Object

Examples:

A not recommended definition with isolation

require "spectus"
require "matchi/raise_exception"

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

See Also:



155
156
157
158
159
160
161
# File 'lib/spectus.rb', line 155

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