module TestBench::Structure

Public Class Methods

error(error, binding) click to toggle source
# File lib/test_bench/structure.rb, line 80
def self.error error, binding
  telemetry = Telemetry::Registry.get binding
  settings = Settings::Registry.get binding

  telemetry.error_raised error

  exit 1 if settings.abort_on_error
end

Public Instance Methods

assert(subject, mod=nil, assert_class: nil, caller_location: nil, &block) click to toggle source
# File lib/test_bench/structure.rb, line 3
def assert subject, mod=nil, assert_class: nil, caller_location: nil, &block
  assert_class ||= Assert
  caller_location ||= caller_locations[0]

  telemetry = Telemetry::Registry.get binding

  unless assert_class.(subject, mod, &block)
    raise Assert::Failed.build caller_location
  end

ensure
  telemetry.asserted
end
comment(prose) click to toggle source
# File lib/test_bench/structure.rb, line 17
def comment prose
  telemetry = Telemetry::Registry.get binding

  telemetry.commented prose
end
context(prose=nil, suppress_exit: nil, &block) click to toggle source
# File lib/test_bench/structure.rb, line 23
def context prose=nil, suppress_exit: nil, &block
  suppress_exit ||= false

  telemetry = Telemetry::Registry.get binding

  unless prose.nil? or prose.is_a? String
    raise TypeError, "Prose must be a String"
  end

  begin
    telemetry.context_entered prose
    block.() if block

  rescue => error
    Structure.error error, binding

  ensure
    nesting = telemetry.context_exited prose

    if nesting.zero? and telemetry.failed?
      exit 1 unless suppress_exit
    end
  end
end
refute(*arguments, &block) click to toggle source
# File lib/test_bench/structure.rb, line 48
def refute *arguments, &block
  assert(*arguments, :assert_class => Assert::Refute, :caller_location => caller_locations[0], &block)
end
test(prose=nil, &block) click to toggle source
# File lib/test_bench/structure.rb, line 52
def test prose=nil, &block
  telemetry = Telemetry::Registry.get binding

  prose ||= 'Test'

  unless prose.is_a? String
    raise TypeError, "Prose must be a String"
  end

  if block.nil?
    telemetry.test_skipped prose
    return
  end

  begin
    telemetry.test_started prose
    block.()
    telemetry.test_passed prose

  rescue => error
    telemetry.test_failed prose
    Structure.error error, binding

  ensure
    telemetry.test_finished prose
  end
end