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(matcher:, negate:) ⇒ Base

Initialize the requirement level class.

Parameters:

  • matcher (#matches?)

    The matcher.

  • negate (Boolean)

    Invert the matcher or not.



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

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

Instance Method Details

#call::Expresenter::Pass

Test result.

Returns:

  • (::Expresenter::Pass)

    A passed spec instance.

Raises:

  • (::Expresenter::Fail)

    A failed spec exception.

See Also:



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

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

  ::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) negate=false>"

Returns:

  • (String)

    The human-readable representation of the definition.



57
58
59
# File 'lib/spectus/requirement/base.rb', line 57

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