class Inferno::Entities::Test

Attributes

result_message[RW]
test_session_id[R]

Public Class Methods

block(&block) click to toggle source
# File lib/inferno/entities/test.rb, line 144
def block(&block)
  return @block unless block_given?

  @block = block
end
Also aliased as: run
default_id() click to toggle source
# File lib/inferno/entities/test.rb, line 152
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_definition) click to toggle source

Define inputs for this Test

@param name [Symbol] name of the input @param other_names [Symbol] array of symbols if specifying multiple inputs @param input_definition [Hash] options for input such as type, description, or title @option input_definition [String] :title Human readable title for input @option input_definition [String] :description Description for the input @option input_definition [String] :type 'text' | 'textarea' @return [void] @example

input :patientid, title: 'Patient ID', description: 'The ID of the patient being searched for'

@example

input :textarea, title: 'Textarea Input Example', type: 'textarea'
Calls superclass method
# File lib/inferno/entities/test.rb, line 116
def input(name, *other_names, **input_definition)
  super

  if other_names.present?
    [name, *other_names].each { |input| attr_reader input }
  else
    attr_reader name
  end
end
method_missing(name, *args, &block) click to toggle source
Calls superclass method
# File lib/inferno/entities/test.rb, line 169
def method_missing(name, *args, &block)
  parent_instance = parent&.new
  if parent_instance.respond_to?(name)
    parent_instance.send(name, *args, &block)
  else
    super
  end
end
new(**params) click to toggle source
# File lib/inferno/entities/test.rb, line 15
def initialize(**params)
  params[:inputs]&.each { |key, value| instance_variable_set("@#{key}", value) }
  @test_session_id = params[:test_session_id]
end
output(*output_definitions) click to toggle source

Define outputs for this Test

@param output_definitions [Symbol] @return [void] @example

output :patient_id, :bearer_token
Calls superclass method
# File lib/inferno/entities/test.rb, line 132
def output(*output_definitions)
  super

  output_definitions.each do |output|
    attr_accessor output
  end
end
reference_hash() click to toggle source
# File lib/inferno/entities/test.rb, line 159
def reference_hash
  {
    test_id: id
  }
end
repository() click to toggle source
# File lib/inferno/entities/test.rb, line 140
def repository
  Inferno::Repositories::Tests.new
end
respond_to_missing?(name, _include_private = false) click to toggle source
# File lib/inferno/entities/test.rb, line 178
def respond_to_missing?(name, _include_private = false)
  parent&.new&.respond_to?(name)
end
run(&block)
Alias for: block
test_count() click to toggle source
# File lib/inferno/entities/test.rb, line 165
def test_count
  1
end

Public Instance Methods

add_message(type, message) click to toggle source
# File lib/inferno/entities/test.rb, line 24
def add_message(type, message)
  messages << { type: type.to_s, message: message }
end
info(message = nil) { || ... } click to toggle source

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.

@param message [String] @return [void] @example

# Add an info message
info 'This message will be added to the test results'

# The message for the failed assertion will be treated as an info
# message. Test exection will continue.
info { assert false == true }
# File lib/inferno/entities/test.rb, line 54
def info(message = nil)
  unless block_given?
    add_message('info', message) unless message.nil?
    return
  end

  yield
rescue Exceptions::AssertionException => e
  add_message('info', e.message)
end
messages() click to toggle source
# File lib/inferno/entities/test.rb, line 20
def messages
  @messages ||= []
end
method_missing(name, *args, &block) click to toggle source
Calls superclass method
# File lib/inferno/entities/test.rb, line 89
def method_missing(name, *args, &block)
  parent_instance = self.class.parent&.new
  if parent_instance.respond_to?(name)
    parent_instance.send(name, *args, &block)
  else
    super
  end
end
output(outputs) click to toggle source

Set output values. Once set, these values will be available to any subsequent tests.

@param outputs [Hash] @return [void] @example

output(patient_id: '5', bearer_token: 'ABC')
# File lib/inferno/entities/test.rb, line 35
def output(outputs)
  outputs.each do |key, value|
    send("#{key}=", value)
  end
end
respond_to_missing?(name, _include_private = false) click to toggle source
# File lib/inferno/entities/test.rb, line 98
def respond_to_missing?(name, _include_private = false)
  self.class.parent&.new&.respond_to?(name)
end
warning(message = nil) { || ... } click to toggle source

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.

@param message [String] @return [void] @example

# Add a warning message
warning 'This message will be added to the test results'

# The message for the failed assertion will be treated as a warning
# message. Test exection will continue.
warning { assert false == true }
# File lib/inferno/entities/test.rb, line 78
def warning(message = nil)
  unless block_given?
    add_message('warning', message) unless message.nil?
    return
  end

  yield
rescue Exceptions::AssertionException => e
  add_message('warning', e.message)
end