Class: Campa::Core::Test

Inherits:
Object
  • Object
show all
Defined in:
lib/campa/core/test.rb

Overview

Searches functions with prefix test_ or test- (case insenstive) in a given context, invoke those and store their results in a Data Structure with the given form:

(
  (success, (test-one, test-two)),
  (failures, (test-three, test-four))
)

In this example we are considering that functions test-one and test-two returned true and functions test-three and test-four returned false.

Instance Method Summary collapse

Constructor Details

#initializeTest

Returns a new instance of Test.



16
17
18
# File 'lib/campa/core/test.rb', line 16

def initialize
  @evaler = Campa::Evaler.new
end

Instance Method Details

#call(*tests, env:) ⇒ Object

Execute functions named test-* or test_* (case insentive) and collect the results.

The param tests can be used to filter specific tests to be executed. For a context where functions test-great-one, test-great-two and test-awful exists, if we want to execute only the great ones, we could do:

Examples:

test = Test.new
test.call("great", env: ctx)

Parameters:

  • tests (Array<String>)

    if given will be used to “filter” functions by name

  • env (Context)

    will be used to search functions named test-* or test_* (case insentive) and also to execute those functions



38
39
40
41
42
43
44
# File 'lib/campa/core/test.rb', line 38

def call(*tests, env:)
  summary = execute_all(tests, env)
  List.new(
    List.new(Symbol.new("success"), List.new(*summary[:success])),
    List.new(Symbol.new("failures"), List.new(*summary[:failures]))
  )
end