Module: Verity::DSL

Includes:
Assertions
Defined in:
lib/verity.rb

Overview

Public: Methods mixed into Object so that ‘test` and `group` are available at the top level in test files.

Instance Method Summary collapse

Methods included from Assertions

#assert, #assert_equal, #assert_in_delta, #assert_includes, #assert_match, #assert_nil, #assert_raises, #assert_same, #refute, #refute_equal, #refute_in_delta, #refute_includes, #refute_match, #refute_nil, #refute_raises, #refute_same

Instance Method Details

#group(title, tags: [], &block) ⇒ Object

Public: Define a named group of tests. Groups may be nested and contribute tags that are inherited by every enclosed test.

title - String group name shown in reporter output. tags - Array of Symbols applied to all tests in this group (default []). block - Block containing nested ‘test` and `group` calls.

Raises ArgumentError if no block is given.



325
326
327
328
329
330
331
332
333
334
335
# File 'lib/verity.rb', line 325

def group(title, tags: [], &block)
  raise ArgumentError, "`group` requires a block" unless block

  loc = caller_locations(1, 1).first
  pushed = false
  Verity.push_group(title, tags: tags, file: loc.path, line: loc.lineno)
  pushed = true
  yield
ensure
  Verity.pop_group if pushed
end

#test(description, tags: [], timeout: nil, requires: [], **resources, &fn) ⇒ Object

Public: Register a single test case. The block is stored and executed later by the Runner.

description - String human-readable test name. tags - Array of Symbols (e.g. :focus, :skip) (default []). timeout - Numeric seconds or nil for no timeout (default nil). If set,

must be a positive finite Numeric (+Complex+ and strings are rejected).

requires - Array of Symbols naming shared preconditions (default []). resources - Hash of keyword arguments forwarded as resource metadata. fn - Block containing assertions and test logic.

Returns the newly registered Verity::Test.



349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
# File 'lib/verity.rb', line 349

def test(description, tags: [], timeout: nil, requires: [], **resources, &fn)
  Verity.validate_test_timeout!(timeout)
  location = caller_locations(1, 1).first
  file = location.path
  line = location.lineno
  fingerprint = Verity::Fingerprint.lookup(line) || Verity::Fingerprint.fallback_fingerprint(file, line)

  Verity::Registry.register(
    Verity::Test.new(
      fingerprint:,
      description:,
      tags:,
      timeout:,
      requires:,
      resources:,
      file:,
      line:,
      fn:,
      group_path: Verity.group_path_for_registration,
      inherited_group_tags: Verity.inherited_group_tags_for_registration,
      group_scopes: Verity.group_scopes_for_registration
    )
  )
end