Class: Inferno::Entities::Test

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
DSL
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

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



107
108
109
110
111
112
113
114
# File 'lib/inferno/entities/test.rb', line 107

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

Instance Attribute Details

#result_messageObject

Returns the value of attribute result_message.



15
16
17
# File 'lib/inferno/entities/test.rb', line 15

def result_message
  @result_message
end

#scratchObject (readonly)

Returns the value of attribute scratch.



16
17
18
# File 'lib/inferno/entities/test.rb', line 16

def scratch
  @scratch
end

#suite_optionsObject (readonly)

Returns the value of attribute suite_options.



16
17
18
# File 'lib/inferno/entities/test.rb', line 16

def suite_options
  @suite_options
end

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

Parameters:

  • block (Proc)

Returns:

  • (Proc)

    the block that is executed when a Test is run



169
170
171
172
173
# File 'lib/inferno/entities/test.rb', line 169

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

  @block = block
end

.input(name, *other_names, **input_params) ⇒ void

This method returns an undefined value.

Define inputs for this Test

Examples:

input :patientid, title: 'Patient ID', description: 'The ID of the patient being searched for'
input :textarea, title: 'Textarea Input Example', type: 'textarea'

Parameters:

  • name (Symbol)

    name of the input

  • other_names (Symbol)

    array of symbols if specifying multiple inputs

  • input_params (Hash)

    options for input such as type, description, or title

Options Hash (**input_params):

  • :title (String)

    Human readable title for input

  • :description (String)

    Description for the input

  • :type (String)

    'text' | 'textarea'



135
136
137
138
139
140
141
142
143
# File 'lib/inferno/entities/test.rb', line 135

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

.output(*output_definitions, **_output_params) ⇒ void

This method returns an undefined value.

Define outputs for this Test

Examples:

output :patient_id, :bearer_token

Parameters:

  • output_definitions (Symbol)
  • _output_params (Hash)

    Unused parameter. Just makes method signature compatible with Inferno::DSL::InputOutputHandling.output



153
154
155
156
157
158
159
# File 'lib/inferno/entities/test.rb', line 153

def output(*output_definitions, **_output_params)
  super

  output_definitions.each do |output|
    attr_accessor output
  end
end

.repositoryObject



161
162
163
# File 'lib/inferno/entities/test.rb', line 161

def repository
  Inferno::Repositories::Tests.new
end

.short_idObject



177
178
179
180
181
182
183
# File 'lib/inferno/entities/test.rb', line 177

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

Instance Method Details

#add_message(type, message) ⇒ Object



31
32
33
# File 'lib/inferno/entities/test.rb', line 31

def add_message(type, message)
  messages << { type: type.to_s, message: format_markdown(message) }
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.

Examples:

# 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 }

Parameters:

  • message (String) (defaults to: nil)


71
72
73
74
75
76
77
78
79
80
# File 'lib/inferno/entities/test.rb', line 71

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

#output(outputs) ⇒ void

This method returns an undefined value.

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

Examples:

output(patient_id: '5', bearer_token: 'ABC')

Parameters:

  • outputs (Hash)


42
43
44
45
46
47
48
# File 'lib/inferno/entities/test.rb', line 42

def output(outputs)
  # TODO: update to track outputs that need to be updated
  outputs.each do |key, value|
    send("#{key}=", value)
    outputs_to_persist[key] = value
  end
end

#outputs_to_persistObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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.



54
55
56
# File 'lib/inferno/entities/test.rb', line 54

def outputs_to_persist
  @outputs_to_persist ||= {}
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.

Examples:

# 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 }

Parameters:

  • message (String) (defaults to: nil)


95
96
97
98
99
100
101
102
103
104
# File 'lib/inferno/entities/test.rb', line 95

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