Class: Spectus::Requirement::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/spectus/requirement/base.rb

Overview

Requirement level’s base class.

Direct Known Subclasses

Optional, Recommended, Required

Instance Method Summary collapse

Constructor Details

#initialize(isolate:, matcher:, negate:) ⇒ Base

Initialize the requirement level class.

Parameters:

  • isolate (Boolean)

    Compute actual in a subprocess.

  • matcher (#matches?)

    The matcher.

  • negate (Boolean)

    Invert the matcher or not.



16
17
18
19
20
# File 'lib/spectus/requirement/base.rb', line 16

def initialize(isolate:, matcher:, negate:)
  @isolate  = isolate
  @matcher  = matcher
  @negate   = negate
end

Instance Method Details

#call(&block) ⇒ ::Expresenter::Pass

Test result.

Returns:

  • (::Expresenter::Pass)

    A passed spec instance.

Raises:

  • (::Expresenter::Fail)

    A failed spec exception.

See Also:



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/spectus/requirement/base.rb', line 30

def call(&block)
  test = ::TestTube.invoke(isolate: @isolate, matcher: @matcher, negate: @negate, &block)

  ::Expresenter.call(passed?(test)).with(
    actual:     test.actual,
    definition: @matcher.to_s,
    error:      test.error,
    expected:   @matcher.expected,
    got:        test.got,
    level:      self.class.level,
    negate:     @negate
  )
end

#inspectString

A string containing a human-readable representation of the definition.

Examples:

The human-readable representation of an absolute requirement.

require "spectus"
require "matchi/be"

definition = Spectus.must Matchi::Be.new(1)
definition.inspect
# => "#<MUST Matchi::Be(1) isolate=false negate=false>"

Returns:

  • (String)

    The human-readable representation of the definition.



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

def inspect
  "#<#{self.class.level} #{@matcher.inspect} isolate=#{@isolate} negate=#{@negate}>"
end