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

Instance Method Summary collapse

Instance Attribute Details

#parentObject

Returns the value of attribute parent.



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

def parent
  @parent
end

#suite_option_requirementsObject (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

Parameters:

  • block (Proc)

Returns:

  • (Proc)

    the block that is executed when a runnable is run



303
304
305
306
307
# File 'lib/inferno/dsl/runnable.rb', line 303

def block(&block)
  return @block unless block_given?

  @block = block
end

#description(new_description = nil) ⇒ String

Set/Get a runnable’s description

Parameters:

  • new_description (String) (defaults to: nil)

Returns:

  • (String)

    the description



235
236
237
238
239
# File 'lib/inferno/dsl/runnable.rb', line 235

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

Raises:



192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/inferno/dsl/runnable.rb', line 192

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

Parameters:

  • new_input_instructions (String) (defaults to: nil)

Returns:

  • (String)

    the input instructions



255
256
257
258
259
# File 'lib/inferno/dsl/runnable.rb', line 255

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)


265
266
267
# File 'lib/inferno/dsl/runnable.rb', line 265

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

#optional?Boolean

The test or group is optional if true

Returns:

  • (Boolean)


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

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)


276
277
278
# File 'lib/inferno/dsl/runnable.rb', line 276

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

#required?Boolean

The test or group is required if true

Returns:

  • (Boolean)


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

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.

Examples:

suite_option :ig_version,
            list_options: [
              {
                label: 'IG v1',
                value: 'ig_v1'
              },
              {
                label: 'IG v2',
                value: 'ig_v2'
              }
            ]

group from: :ig_v1_group,
      required_suite_options: { ig_version: 'ig_v1' }

group from: :ig_v2_group do
  required_suite_options ig_version: 'ig_v2'
end

Parameters:

  • suite_option_requirements (Hash)


448
449
450
451
452
453
# File 'lib/inferno/dsl/runnable.rb', line 448

def required_suite_options(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

Examples:

resume_test_route :get, '/launch', tags: ['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.

  • tags (Array<String>) (defaults to: [])

    a list of tags to assign to the request

  • result (String) (defaults to: 'pass')

    the result for the waiting test. Must be one of: ‘pass’, ‘fail’, ‘skip’, ‘omit’, ‘cancel’

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:



359
360
361
362
363
364
365
366
367
# File 'lib/inferno/dsl/runnable.rb', line 359

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, 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

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.



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

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

Parameters:

  • new_short_description (String) (defaults to: nil)

Returns:

  • (String)

    the one-sentence description



245
246
247
248
249
# File 'lib/inferno/dsl/runnable.rb', line 245

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



225
226
227
228
229
# File 'lib/inferno/dsl/runnable.rb', line 225

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.

Examples:

suite_endpoint :post, '/my_suite_endpoint', MySuiteEndpoint

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.

  • a (Class)

    subclass of Inferno::DSL::SuiteEndpoint

See Also:



383
384
385
# File 'lib/inferno/dsl/runnable.rb', line 383

def suite_endpoint(method, path, endpoint_class)
  route(method, path, endpoint_class)
end

#title(new_title = nil) ⇒ String

Set/Get a runnable’s title

Parameters:

  • new_title (String) (defaults to: nil)

Returns:

  • (String)

    the title



215
216
217
218
219
# File 'lib/inferno/dsl/runnable.rb', line 215

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

  @title = new_title
end