Class: Inferno::Entities::Test
- Inherits:
-
Object
- Object
- Inferno::Entities::Test
- Extended by:
- Forwardable
- Includes:
- DSL, Utils::MarkdownFormatter
- 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
-
.block(&block) ⇒ Proc
(also: run)
Set/Get the block that is executed when a Test is run.
- .default_id ⇒ Object
-
.input(name, *other_names, **input_params) ⇒ void
Define inputs for this Test.
- .method_missing(name, *args) ⇒ 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
-
#add_message(type, message) ⇒ void
Add a message to the result.
-
#info(message = nil) ⇒ void
Add an informational message to the results of a test.
-
#initialize(**params) ⇒ Test
constructor
A new instance of Test.
- #messages ⇒ Object
- #method_missing(name, *args) ⇒ 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
-
#warning(message = nil) ⇒ void
Add a warning message to the results of a test.
Methods included from Utils::MarkdownFormatter
Methods included from DSL
Constructor Details
#initialize(**params) ⇒ Test
Returns a new instance of Test.
19 20 21 22 23 24 |
# File 'lib/inferno/entities/test.rb', line 19 def initialize(**params) params[:inputs]&.each { |key, value| instance_variable_set("@#{key}", value) } @scratch = params[:scratch] @test_session_id = params[:test_session_id] = params[:suite_options].presence || {} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
111 112 113 114 115 116 117 118 |
# File 'lib/inferno/entities/test.rb', line 111 def method_missing(name, *args, &) parent_instance = self.class.parent&.new if parent_instance.respond_to?(name) parent_instance.send(name, *args, &) else super end end |
Instance Attribute Details
#result_message ⇒ Object
Returns the value of attribute result_message.
15 16 17 |
# File 'lib/inferno/entities/test.rb', line 15 def end |
#scratch ⇒ Object (readonly)
Returns the value of attribute scratch.
16 17 18 |
# File 'lib/inferno/entities/test.rb', line 16 def scratch @scratch end |
#suite_options ⇒ Object (readonly)
Returns the value of attribute suite_options.
16 17 18 |
# File 'lib/inferno/entities/test.rb', line 16 def end |
#test_session_id ⇒ Object (readonly)
Returns the value of attribute test_session_id.
16 17 18 |
# File 'lib/inferno/entities/test.rb', line 16 def test_session_id @test_session_id end |
Class Method Details
.block(&block) ⇒ Proc Also known as: run
Set/Get the block that is executed when a Test is run
174 175 176 177 178 |
# File 'lib/inferno/entities/test.rb', line 174 def block(&block) return @block unless block_given? @block = block end |
.default_id ⇒ Object
191 192 193 194 195 196 |
# File 'lib/inferno/entities/test.rb', line 191 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
139 140 141 142 143 144 145 146 147 |
# File 'lib/inferno/entities/test.rb', line 139 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, *args) ⇒ Object
212 213 214 215 216 217 218 219 |
# File 'lib/inferno/entities/test.rb', line 212 def method_missing(name, *args, &) parent_instance = parent&.new if parent_instance.respond_to?(name) parent_instance.send(name, *args, &) else super end end |
.output(*output_definitions, **_output_params) ⇒ void
This method returns an undefined value.
Define outputs for this Test
157 158 159 160 161 162 163 |
# File 'lib/inferno/entities/test.rb', line 157 def output(*output_definitions, **_output_params) super output_definitions.each do |output| attr_accessor output end end |
.reference_hash ⇒ Object
199 200 201 202 203 |
# File 'lib/inferno/entities/test.rb', line 199 def reference_hash { test_id: id } end |
.repository ⇒ Object
166 167 168 |
# File 'lib/inferno/entities/test.rb', line 166 def repository Inferno::Repositories::Tests.new end |
.respond_to_missing?(name, _include_private = false) ⇒ Boolean
222 223 224 |
# File 'lib/inferno/entities/test.rb', line 222 def respond_to_missing?(name, _include_private = false) parent&.new&.respond_to?(name) end |
.short_id ⇒ Object
182 183 184 185 186 187 188 |
# File 'lib/inferno/entities/test.rb', line 182 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
207 208 209 |
# File 'lib/inferno/entities/test.rb', line 207 def test_count(_ = nil) 1 end |
Instance Method Details
#add_message(type, message) ⇒ void
This method returns an undefined value.
Add a message to the result.
36 37 38 |
# File 'lib/inferno/entities/test.rb', line 36 def (type, ) << { type: type.to_s, message: format_markdown() } end |
#info(message = nil) ⇒ void
This method returns an undefined value.
Add an informational message to the results of a test. If passed a block, a failed assertion will become an info message and test execution will continue.
75 76 77 78 79 80 81 82 83 84 |
# File 'lib/inferno/entities/test.rb', line 75 def info( = nil) unless block_given? ('info', ) unless .nil? return end yield rescue Exceptions::AssertionException => e ('info', e.) end |
#messages ⇒ Object
27 28 29 |
# File 'lib/inferno/entities/test.rb', line 27 def ||= [] end |
#output(outputs) ⇒ void
This method returns an undefined value.
Set output values. Once set, these values will be available to any subsequent tests.
47 48 49 50 51 52 |
# File 'lib/inferno/entities/test.rb', line 47 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.
58 59 60 |
# File 'lib/inferno/entities/test.rb', line 58 def outputs_to_persist @outputs_to_persist ||= {} end |
#respond_to_missing?(name, _include_private = false) ⇒ Boolean
121 122 123 |
# File 'lib/inferno/entities/test.rb', line 121 def respond_to_missing?(name, _include_private = false) self.class.parent&.new&.respond_to?(name) end |
#warning(message = nil) ⇒ void
This method returns an undefined value.
Add a warning message to the results of a test. If passed a block, a failed assertion will become a warning message and test execution will continue.
99 100 101 102 103 104 105 106 107 108 |
# File 'lib/inferno/entities/test.rb', line 99 def warning( = nil) unless block_given? ('warning', ) unless .nil? return end yield rescue Exceptions::AssertionException => e ('warning', e.) end |