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(isolation: @isolate, matcher: @matcher, negate: @negate, &block)

  ::Expresenter.call(passed?(test)).with(
    actual:   test.actual,
    error:    test.error,
    expected: @matcher.expected,
    got:      test.got,
    level:    self.class.level,
    matcher:  @matcher.class.to_sym,
    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/helper"

include Matchi::Helper

definition = Spectus.must equal 1
definition.inspect
# => #<MUST Matchi::Matcher::Equal(1) isolate=false negate=false>

Returns:

  • (String)

    The human-readable representation of the definition.


61
62
63
# File 'lib/spectus/requirement/base.rb', line 61

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