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/helper"

include Matchi::Helper

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

Parameters:

  • matcher (#matches?)

    The matcher.

Returns:


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

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/helper"

include Matchi::Helper

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

See Also:


219
220
221
222
223
224
225
# File 'lib/spectus.rb', line 219

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/helper"

include Matchi::Helper

Spectus.must eql "FOO"
# => #<MUST Matchi::Matcher::Eql("FOO") isolate=false negate=false>

Parameters:

  • matcher (#matches?)

    The matcher.

Returns:


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

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/helper"

include Matchi::Helper

Spectus.must! eql "FOO"
# => #<MUST Matchi::Matcher::Eql("FOO") isolate=true negate=false>

See Also:


44
45
46
47
48
49
50
# File 'lib/spectus.rb', line 44

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/helper"

include Matchi::Helper

Spectus.must_not equal 42
# => #<MUST Matchi::Matcher::Equal(42) isolate=false negate=true>

Parameters:

  • matcher (#matches?)

    The matcher.

Returns:


66
67
68
69
70
71
72
# File 'lib/spectus.rb', line 66

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/helper"

include Matchi::Helper

Spectus.must_not! equal 42
# => #<MUST Matchi::Matcher::Equal(42) isolate=true negate=true>

See Also:


84
85
86
87
88
89
90
# File 'lib/spectus.rb', line 84

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/helper"

include Matchi::Helper

Spectus.should equal true
# => #<SHOULD Matchi::Matcher::Equal(true) isolate=false negate=false>

Parameters:

  • matcher (#matches?)

    The matcher.

Returns:


108
109
110
111
112
113
114
# File 'lib/spectus.rb', line 108

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/helper"

include Matchi::Helper

Spectus.should! equal true
# => #<SHOULD Matchi::Matcher::Equal(true) isolate=true negate=false>

See Also:


126
127
128
129
130
131
132
# File 'lib/spectus.rb', line 126

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/helper"

include Matchi::Helper

Spectus.should_not raise_exception NoMethodError
# => #<SHOULD Matchi::Matcher::RaiseException(NoMethodError) isolate=false negate=true>

Parameters:

  • matcher (#matches?)

    The matcher.

Returns:


152
153
154
155
156
157
158
# File 'lib/spectus.rb', line 152

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/helper"

include Matchi::Helper

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

See Also:


170
171
172
173
174
175
176
# File 'lib/spectus.rb', line 170

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