Module: Inferno::DSL::Runnable
- Included in:
- Entities::TestGroup, Entities::TestSuite
- Defined in:
- lib/inferno/dsl/runnable.rb
Overview
This module contains the DSL for defining child entities in the test definition framework.
Instance Attribute Summary collapse
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#suite_option_requirements ⇒ Object
readonly
Returns the value of attribute suite_option_requirements.
Instance Method Summary collapse
-
#block(&block) ⇒ Proc
(also: #run)
Set/Get the block that is executed when a runnable is run.
-
#deep_dup(value) ⇒ Object
Recursively duplicate arrays/hashes to prevent them from being shared across different runnables.
-
#description(new_description = nil) ⇒ String
Set/Get a runnable’s description.
-
#id(new_id = nil) ⇒ String, Symbol
Set/Get a runnable’s id.
-
#input_instructions(new_input_instructions = nil) ⇒ String
Set/Get a runnable’s input instructions.
-
#optional(optional = true) ⇒ void
Mark as optional.
-
#optional? ⇒ Boolean
The test or group is optional if true.
-
#remove(id_to_remove) ⇒ Object
Remove a child test/group.
-
#reorder(child_id, new_index) ⇒ Object
Move a child test/group to a new position within the children list.
-
#replace(id_to_replace, replacement_id) {|Inferno::TestGroup, Inferno::Test| ... } ⇒ Object
Replace a child test/group.
-
#required(required = true) ⇒ void
Mark as required.
-
#required? ⇒ Boolean
The test or group is required if true.
-
#required_suite_options(suite_option_requirements) ⇒ void
Set/get suite options required for this runnable to be executed.
-
#resume_test_route(method, path, tags: [], result: 'pass') { ... } ⇒ void
Create a route which will resume a test run when a request is received.
-
#route(method, path, handler) ⇒ void
Create a route to handle a request.
-
#short_description(new_short_description = nil) ⇒ String
Set/Get a runnable’s short one-sentence description.
-
#short_title(new_short_title = nil) ⇒ String
Set/Get a runnable’s short title.
-
#suite_endpoint(method, path, endpoint_class) ⇒ void
Create an endpoint to receive incoming requests during a Test Run.
-
#title(new_title = nil) ⇒ String
Set/Get a runnable’s title.
-
#verifies_requirements(*requirement_ids) ⇒ Array<String>
Set/Get the IDs of requirements verified by this runnable Set with [] to clear the list.
Instance Attribute Details
#parent ⇒ Object
Returns the value of attribute parent.
12 13 14 |
# File 'lib/inferno/dsl/runnable.rb', line 12 def parent @parent end |
#suite_option_requirements ⇒ Object (readonly)
Returns the value of attribute suite_option_requirements.
13 14 15 |
# File 'lib/inferno/dsl/runnable.rb', line 13 def suite_option_requirements @suite_option_requirements end |
Instance Method Details
#block(&block) ⇒ Proc Also known as: run
Set/Get the block that is executed when a runnable is run
320 321 322 323 324 |
# File 'lib/inferno/dsl/runnable.rb', line 320 def block(&block) return @block unless block_given? @block = block end |
#deep_dup(value) ⇒ Object
Recursively duplicate arrays/hashes to prevent them from being shared across different runnables
52 53 54 55 56 57 58 59 60 |
# File 'lib/inferno/dsl/runnable.rb', line 52 def deep_dup(value) if value.is_a? Array value.map { |element| deep_dup(element) } elsif value.is_a? Hash value.transform_values { |element| deep_dup(element) } else value.dup end end |
#description(new_description = nil) ⇒ String
Set/Get a runnable’s description
237 238 239 240 241 |
# File 'lib/inferno/dsl/runnable.rb', line 237 def description(new_description = nil) return @description if new_description.nil? @description = format_markdown(new_description) end |
#id(new_id = nil) ⇒ String, Symbol
Set/Get a runnable’s id
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/inferno/dsl/runnable.rb', line 194 def id(new_id = nil) return @id if new_id.nil? && @id.present? prefix = if parent "#{parent.id}-" else '' end @base_id = new_id || @base_id || default_id final_id = "#{prefix}#{@base_id}" raise Exceptions::InvalidRunnableIdException, final_id if final_id.length > 255 @id = final_id end |
#input_instructions(new_input_instructions = nil) ⇒ String
Set/Get a runnable’s input instructions
257 258 259 260 261 |
# File 'lib/inferno/dsl/runnable.rb', line 257 def input_instructions(new_input_instructions = nil) return @input_instructions if new_input_instructions.nil? @input_instructions = format_markdown(new_input_instructions) end |
#optional(optional = true) ⇒ void
This method returns an undefined value.
Mark as optional. Tests are required by default.
282 283 284 |
# File 'lib/inferno/dsl/runnable.rb', line 282 def optional(optional = true) # rubocop:disable Style/OptionalBooleanParameter @optional = optional end |
#optional? ⇒ Boolean
The test or group is optional if true
300 301 302 |
# File 'lib/inferno/dsl/runnable.rb', line 300 def optional? !!@optional end |
#remove(id_to_remove) ⇒ Object
Remove a child test/group
536 537 538 539 540 |
# File 'lib/inferno/dsl/runnable.rb', line 536 def remove(id_to_remove) removed = children.select { |child| child.id.to_s.end_with? id_to_remove.to_s } children.reject! { |child| child.id.to_s.end_with? id_to_remove.to_s } removed.each(&:remove_self_from_repository) end |
#reorder(child_id, new_index) ⇒ Object
Move a child test/group to a new position within the children list.
484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 |
# File 'lib/inferno/dsl/runnable.rb', line 484 def reorder(child_id, new_index) index = children.find_index { |child| child.id.to_s.end_with? child_id.to_s } raise Exceptions::RunnableChildNotFoundException.new(child_id, self) unless index unless new_index.between?(0, children.length - 1) Inferno::Application[:logger].error <<~ERROR Error trying to reorder children for #{self}: new_index #{new_index} for #{child_id} is out of range (must be between 0 and #{children.length - 1}) ERROR return end child = children.delete_at(index) children.insert(new_index, child) end |
#replace(id_to_replace, replacement_id) {|Inferno::TestGroup, Inferno::Test| ... } ⇒ Object
Replace a child test/group
513 514 515 516 517 518 519 520 521 522 523 524 525 |
# File 'lib/inferno/dsl/runnable.rb', line 513 def replace(id_to_replace, replacement_id, &) index = children.find_index { |child| child.id.to_s.end_with? id_to_replace.to_s } raise Exceptions::RunnableChildNotFoundException.new(id_to_replace, self) unless index if children[index] < Inferno::TestGroup group(from: replacement_id, &) else test(from: replacement_id, &) end remove(id_to_replace) children.insert(index, children.pop) end |
#required(required = true) ⇒ void
This method returns an undefined value.
Mark as required
Tests are required by default. This method is provided to make an existing optional test required.
293 294 295 |
# File 'lib/inferno/dsl/runnable.rb', line 293 def required(required = true) # rubocop:disable Style/OptionalBooleanParameter @optional = !required end |
#required? ⇒ Boolean
The test or group is required if true
307 308 309 |
# File 'lib/inferno/dsl/runnable.rb', line 307 def required? !optional? end |
#required_suite_options(suite_option_requirements) ⇒ void
This method returns an undefined value.
Set/get suite options required for this runnable to be executed.
470 471 472 473 474 475 |
# File 'lib/inferno/dsl/runnable.rb', line 470 def (suite_option_requirements) @suite_option_requirements = suite_option_requirements.map do |key, value| DSL::SuiteOption.new(id: key, value:) end end |
#resume_test_route(method, path, tags: [], result: 'pass') { ... } ⇒ void
This method returns an undefined value.
Create a route which will resume a test run when a request is received
381 382 383 384 385 386 387 388 389 |
# File 'lib/inferno/dsl/runnable.rb', line 381 def resume_test_route(method, path, tags: [], result: 'pass', &block) route_class = Class.new(ResumeTestRoute) do |klass| klass.singleton_class.instance_variable_set(:@test_run_identifier_block, block) klass.singleton_class.instance_variable_set(:@tags, ) klass.singleton_class.instance_variable_set(:@result, result) end route(method, path, route_class) end |
#route(method, path, handler) ⇒ void
This method returns an undefined value.
Create a route to handle a request
423 424 425 |
# File 'lib/inferno/dsl/runnable.rb', line 423 def route(method, path, handler) Inferno.routes << { method:, path:, handler:, suite: } end |
#short_description(new_short_description = nil) ⇒ String
Set/Get a runnable’s short one-sentence description
247 248 249 250 251 |
# File 'lib/inferno/dsl/runnable.rb', line 247 def short_description(new_short_description = nil) return @short_description if new_short_description.nil? @short_description = format_markdown(new_short_description) end |
#short_title(new_short_title = nil) ⇒ String
Set/Get a runnable’s short title
227 228 229 230 231 |
# File 'lib/inferno/dsl/runnable.rb', line 227 def short_title(new_short_title = nil) return @short_title if new_short_title.nil? @short_title = new_short_title end |
#suite_endpoint(method, path, endpoint_class) ⇒ void
This method returns an undefined value.
Create an endpoint to receive incoming requests during a Test Run.
405 406 407 |
# File 'lib/inferno/dsl/runnable.rb', line 405 def suite_endpoint(method, path, endpoint_class) route(method, path, endpoint_class) end |
#title(new_title = nil) ⇒ String
Set/Get a runnable’s title
217 218 219 220 221 |
# File 'lib/inferno/dsl/runnable.rb', line 217 def title(new_title = nil) return @title if new_title.nil? @title = new_title end |
#verifies_requirements(*requirement_ids) ⇒ Array<String>
Set/Get the IDs of requirements verified by this runnable Set with [] to clear the list
268 269 270 271 272 273 274 275 276 |
# File 'lib/inferno/dsl/runnable.rb', line 268 def verifies_requirements(*requirement_ids) if requirement_ids.empty? @requirement_ids || [] elsif requirement_ids == [[]] @requirement_ids = [] else @requirement_ids = requirement_ids end end |