Class: Inferno::Entities::Test
- Inherits:
-
Object
- Object
- Inferno::Entities::Test
- Extended by:
- Forwardable
- Includes:
- DSL
- Defined in:
- lib/inferno/entities/test.rb
Constant Summary
Constants included from DSL
DSL::EXTENDABLE_DSL_MODULES, DSL::INCLUDABLE_DSL_MODULES
Instance Attribute Summary collapse
-
#result_message ⇒ Object
Returns the value of attribute result_message.
-
#scratch ⇒ Object
readonly
Returns the value of attribute scratch.
-
#suite_options ⇒ Object
readonly
Returns the value of attribute suite_options.
-
#test_session_id ⇒ Object
readonly
Returns the value of attribute test_session_id.
Class Method Summary collapse
- .default_id ⇒ Object
-
.input(name, *other_names, **input_params) ⇒ void
Define inputs for this Test.
- .method_missing(name) ⇒ Object
-
.output(*output_definitions, **_output_params) ⇒ void
Define outputs for this Test.
- .reference_hash ⇒ Object
- .repository ⇒ Object
- .respond_to_missing?(name, _include_private = false) ⇒ Boolean
- .short_id ⇒ Object
-
.test_count(_ = nil) ⇒ Object
Has an unused argument to match the method signature of Runnable#test_count.
Instance Method Summary collapse
-
#initialize(**params) ⇒ Test
constructor
A new instance of Test.
- #method_missing(name) ⇒ Object
-
#output(outputs) ⇒ void
Set output values.
-
#outputs_to_persist ⇒ Object
A hash containing outputs that have been set during execution and need to be persisted.
- #respond_to_missing?(name, _include_private = false) ⇒ Boolean
Methods included from DSL
Constructor Details
#initialize(**params) ⇒ Test
Returns a new instance of Test.
17 18 19 20 21 22 |
# File 'lib/inferno/entities/test.rb', line 17 def initialize(**params) params[:inputs]&.each { |key, value| instance_variable_set("@#{key}", value) } @scratch = params[:scratch] @test_session_id = params[:test_session_id] @suite_options = params[:suite_options].presence || {} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name) ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/inferno/entities/test.rb', line 47 def method_missing(name, ...) parent_instance = self.class.parent&.new if parent_instance.respond_to?(name) parent_instance.send(name, ...) else super end end |
Instance Attribute Details
#result_message ⇒ Object
Returns the value of attribute result_message.
13 14 15 |
# File 'lib/inferno/entities/test.rb', line 13 def @result_message end |
#scratch ⇒ Object (readonly)
Returns the value of attribute scratch.
14 15 16 |
# File 'lib/inferno/entities/test.rb', line 14 def scratch @scratch end |
#suite_options ⇒ Object (readonly)
Returns the value of attribute suite_options.
14 15 16 |
# File 'lib/inferno/entities/test.rb', line 14 def @suite_options end |
#test_session_id ⇒ Object (readonly)
Returns the value of attribute test_session_id.
14 15 16 |
# File 'lib/inferno/entities/test.rb', line 14 def test_session_id @test_session_id end |
Class Method Details
.default_id ⇒ Object
115 116 117 118 119 120 |
# File 'lib/inferno/entities/test.rb', line 115 def default_id return name if name.present? suffix = parent ? (parent.tests.find_index(self) + 1).to_s.rjust(2, '0') : SecureRandom.uuid "Test#{suffix}" end |
.input(name, *other_names, **input_params) ⇒ void
This method returns an undefined value.
Define inputs for this Test
75 76 77 78 79 80 81 82 83 |
# File 'lib/inferno/entities/test.rb', line 75 def input(name, *other_names, **input_params) super if other_names.present? [name, *other_names].each { |input| attr_reader input } else attr_reader name end end |
.method_missing(name) ⇒ Object
136 137 138 139 140 141 142 143 |
# File 'lib/inferno/entities/test.rb', line 136 def method_missing(name, ...) parent_instance = parent&.new if parent_instance.respond_to?(name) parent_instance.send(name, ...) else super end end |
.output(*output_definitions, **_output_params) ⇒ void
This method returns an undefined value.
Define outputs for this Test
93 94 95 96 97 98 99 |
# File 'lib/inferno/entities/test.rb', line 93 def output(*output_definitions, **_output_params) super output_definitions.each do |output| attr_accessor output end end |
.reference_hash ⇒ Object
123 124 125 126 127 |
# File 'lib/inferno/entities/test.rb', line 123 def reference_hash { test_id: id } end |
.repository ⇒ Object
102 103 104 |
# File 'lib/inferno/entities/test.rb', line 102 def repository Inferno::Repositories::Tests.new end |
.respond_to_missing?(name, _include_private = false) ⇒ Boolean
146 147 148 |
# File 'lib/inferno/entities/test.rb', line 146 def respond_to_missing?(name, _include_private = false) parent&.new&.respond_to?(name) end |
.short_id ⇒ Object
106 107 108 109 110 111 112 |
# File 'lib/inferno/entities/test.rb', line 106 def short_id @short_id ||= begin prefix = parent.respond_to?(:short_id) ? "#{parent.short_id}." : '' suffix = parent ? (parent.tests.find_index(self) + 1).to_s.rjust(2, '0') : 'x' "#{prefix}#{suffix}" end end |
.test_count(_ = nil) ⇒ Object
Has an unused argument to match the method signature of Runnable#test_count
131 132 133 |
# File 'lib/inferno/entities/test.rb', line 131 def test_count(_ = nil) 1 end |
Instance Method Details
#output(outputs) ⇒ void
This method returns an undefined value.
Set output values. Once set, these values will be available to any subsequent tests.
31 32 33 34 35 36 |
# File 'lib/inferno/entities/test.rb', line 31 def output(outputs) outputs.each do |key, value| send("#{key}=", value) outputs_to_persist[key] = value end end |
#outputs_to_persist ⇒ Object
A hash containing outputs that have been set during execution and need to be persisted. A test may not always update all outputs, so this is used to prevent overwriting an output with nil when it wasn’t updated.
42 43 44 |
# File 'lib/inferno/entities/test.rb', line 42 def outputs_to_persist @outputs_to_persist ||= {} end |
#respond_to_missing?(name, _include_private = false) ⇒ Boolean
57 58 59 |
# File 'lib/inferno/entities/test.rb', line 57 def respond_to_missing?(name, _include_private = false) self.class.parent&.new&.respond_to?(name) end |