Class: Test

Inherits:
Gloo::Core::Obj
  • Object
show all
Defined in:
lib/test.rb

Overview

A gloo unit test object

Constant Summary collapse

KEYWORD =
'test'.freeze
TEST_DESC =
'description'.freeze
ON_TEST_EVENT =
'on_test'.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.doc_dataObject

Get the object's documentation data.



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/test.rb', line 98

def self.doc_data
  {
    :name => KEYWORD,
    :shortcut => KEYWORD,
    :description => 'A single gloo test.',
    :children => [
      'description (string) — A textual description of the test and desired outcome, used in output if there is an error.',
      'on_test (script) — The script to run when the test is executed. Note that the normal way to run tests is with gloo --test.'
    ],
    :examples => <<~EXAMPLES.strip
      #
      # Basic tests
      #
      tests [can] :
        basic [can] :

          on_load [script] :
            log 'Include functionality for all test in on_load' (debug)

          assert_noop [test] :
            description [string] : Assert no operation
            on_test [script] :
              noop
              assert 'noop should be true'
    EXAMPLES
  }
end

.messagesObject

Get a list of message names that this object receives.



63
64
65
# File 'lib/test.rb', line 63

def self.messages
  return super # + [ 'run' ]
end

.short_typenameObject

The short name of the object type. Same as the typename.



22
23
24
# File 'lib/test.rb', line 22

def self.short_typename
  return KEYWORD
end

.typenameObject

The name of the object type.



14
15
16
# File 'lib/test.rb', line 14

def self.typename
  return KEYWORD
end

Instance Method Details

#add_children_on_create?Boolean

Does this object have children to add when an object is created in interactive mode? This does not apply during obj load, etc.

Returns:

  • (Boolean)


42
43
44
# File 'lib/test.rb', line 42

def add_children_on_create?
  return true
end

#add_default_childrenObject

Add children to this object. This is used by containers to add children needed for default configurations.



49
50
51
52
53
# File 'lib/test.rb', line 49

def add_default_children
  fac = @engine.factory
  fac.create_string TEST_DESC, '', self
  fac.create_script ON_TEST_EVENT, '', self
end

#run_on_testObject

Run the on_test script.



84
85
86
87
88
89
# File 'lib/test.rb', line 84

def run_on_test
  o = find_child ON_TEST_EVENT
  return unless o

  Gloo::Exec::Dispatch.message( @engine, 'run', o )
end

#run_testObject

Run the test.



70
71
72
73
74
75
76
77
78
79
# File 'lib/test.rb', line 70

def run_test
  result = Result.new( @engine, self )
  @engine.context_object = result
  run_on_test
  @engine.context_object = nil

  result.show_result_symbol

  return result
end

#test_descObject

Get the test description.



29
30
31
32
# File 'lib/test.rb', line 29

def test_desc
  o = find_child TEST_DESC
  return o ? o.value : 'Unknown'
end