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.

Constant Summary collapse

VARIABLES_NOT_TO_COPY =

Class instance variables are used to hold the metadata for Runnable classes. When inheriting from a Runnable class, these class instance variables need to be copied. Some instance variables should not be copied, and will need to be repopulated from scratch on the new class. Any child Runnable classes will themselves need to be subclassed so that their parent can be updated.

[
  :@id, # New runnable will have a different id
  :@parent, # New runnable unlikely to have the same parent
  :@all_children, # New subclasses have to be made for each child
  :@test_count, # Needs to be recalculated
  :@config, # Needs to be set by calling .config, which does extra work
  :@available_inputs, # Needs to be recalculated
  :@children_available_inputs # Needs to be recalculated
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#parentObject

Returns the value of attribute parent.



11
12
13
# File 'lib/inferno/dsl/runnable.rb', line 11

def parent
  @parent
end

#suite_option_requirementsObject (readonly)

Returns the value of attribute suite_option_requirements.



12
13
14
# File 'lib/inferno/dsl/runnable.rb', line 12

def suite_option_requirements
  @suite_option_requirements
end

Instance Method Details

#children(selected_suite_options = []) ⇒ Object



408
409
410
411
412
413
414
415
416
417
418
419
420
# File 'lib/inferno/dsl/runnable.rb', line 408

def children(selected_suite_options = [])
  return all_children if selected_suite_options.blank?

  all_children.select do |child|
    requirements = child.suite_option_requirements

    if requirements.blank?
      true
    else
      requirements.all? { |requirement| selected_suite_options.include? requirement }
    end
  end
end

#description(new_description = nil) ⇒ String

Set/Get a runnable's description

Parameters:

  • new_description (String) (defaults to: nil)

Returns:

  • (String)

    the description



240
241
242
243
244
# File 'lib/inferno/dsl/runnable.rb', line 240

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

Parameters:

  • new_id (String, Symbol) (defaults to: nil)

Returns:

  • (String, Symbol)

    the id



201
202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/inferno/dsl/runnable.rb', line 201

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

  @id = "#{prefix}#{@base_id}"
end

#input_instructions(new_input_instructions = nil) ⇒ String

Set/Get a runnable's input instructions

Parameters:

  • new_input_instructions (String) (defaults to: nil)

Returns:

  • (String)

    the input instructions



260
261
262
263
264
# File 'lib/inferno/dsl/runnable.rb', line 260

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.

Parameters:

  • optional (Boolean) (defaults to: true)


271
272
273
# File 'lib/inferno/dsl/runnable.rb', line 271

def optional(optional = true) # rubocop:disable Style/OptionalBooleanParameter
  @optional = optional
end

#optional?Boolean

The test or group is optional if true

Returns:

  • (Boolean)


289
290
291
# File 'lib/inferno/dsl/runnable.rb', line 289

def optional?
  !!@optional
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.

Parameters:

  • required (Boolean) (defaults to: true)


282
283
284
# File 'lib/inferno/dsl/runnable.rb', line 282

def required(required = true) # rubocop:disable Style/OptionalBooleanParameter
  @optional = !required
end

#required?Boolean

The test or group is required if true

Returns:

  • (Boolean)


296
297
298
# File 'lib/inferno/dsl/runnable.rb', line 296

def required?
  !optional?
end

#required_suite_options(suite_option_requirements) ⇒ Object



401
402
403
404
405
406
# File 'lib/inferno/dsl/runnable.rb', line 401

def required_suite_options(suite_option_requirements)
  @suite_option_requirements =
    suite_option_requirements.map do |key, value|
      DSL::SuiteOption.new(id: key, value: value)
    end
end

#resume_test_route(method, path) { ... } ⇒ Object

Create a route which will resume a test run when a request is received

Examples:

resume_test_route :get, '/launch' do
  request.query_parameters['iss']
end

test do
  input :issuer
  receives_request :launch

  run do
    wait(
      identifier: issuer,
      message: "Wating to receive a request with an issuer of #{issuer}"
    )
  end
end

Parameters:

  • method (Symbol)

    the HTTP request type (:get, :post, etc.) for the incoming request

  • path (String)

    the path for this request. The route will be served with a prefix of /custom/TEST_SUITE_ID to prevent path conflicts. Any of the path options available in Hanami Router can be used here.

Yields:

  • This method takes a block which must return the identifier defined when a test was set to wait for the test run that hit this route. The block has access to the request method which returns a Entities::Request object with the information for the incoming request.

See Also:



355
356
357
358
359
360
361
362
# File 'lib/inferno/dsl/runnable.rb', line 355

def resume_test_route(method, path, &block)
  route_class = Class.new(ResumeTestRoute) do
    define_method(:test_run_identifier, &block)
    define_method(:request_name, -> { options[:name] })
  end

  route(method, path, route_class)
end

#route(method, path, handler) ⇒ Object

Create a route to handle a request

Parameters:

  • method (Symbol)

    the HTTP request type (:get, :post, etc.) for the incoming request. :all will accept all HTTP request types.

  • path (String)

    the path for this request. The route will be served with a prefix of /custom/TEST_SUITE_ID to prevent path conflicts. Any of the path options available in Hanami Router can be used here.

  • handler (#call)

    the route handler. This can be any Rack compatible object (e.g. a Proc object, a Sinatra app) as described in the Hanami Router documentation.



377
378
379
# File 'lib/inferno/dsl/runnable.rb', line 377

def route(method, path, handler)
  Inferno.routes << { method: method, path: path, handler: handler, suite: suite }
end

#short_description(new_short_description = nil) ⇒ String

Set/Get a runnable's short one-sentence description

Parameters:

  • new_short_description (String) (defaults to: nil)

Returns:

  • (String)

    the one-sentence description



250
251
252
253
254
# File 'lib/inferno/dsl/runnable.rb', line 250

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

Parameters:

  • new_short_title (String) (defaults to: nil)

Returns:

  • (String)

    the short title



230
231
232
233
234
# File 'lib/inferno/dsl/runnable.rb', line 230

def short_title(new_short_title = nil)
  return @short_title if new_short_title.nil?

  @short_title = new_short_title
end

#title(new_title = nil) ⇒ String

Set/Get a runnable's title

Parameters:

  • new_title (String) (defaults to: nil)

Returns:

  • (String)

    the title



220
221
222
223
224
# File 'lib/inferno/dsl/runnable.rb', line 220

def title(new_title = nil)
  return @title if new_title.nil?

  @title = new_title
end

#validator_url(url = nil) ⇒ Object



310
311
312
313
314
# File 'lib/inferno/dsl/runnable.rb', line 310

def validator_url(url = nil)
  return @validator_url ||= parent&.validator_url if url.nil?

  @validator_url = url
end