Module: Inferno::DSL::Messages

Included in:
Assertions, FHIRClient, Entities::TestGroup, Entities::TestSuite
Defined in:
lib/inferno/dsl/messages.rb

Overview

This module contains methods to add meessages to runnable results

Instance Method Summary collapse

Instance Method Details

#add_message(type, message) ⇒ void

This method returns an undefined value.

Add a message to the result.

Parameters:

  • type (String)

    error, warning, or info

  • message (String)


28
29
30
# File 'lib/inferno/dsl/messages.rb', line 28

def add_message(type, message)
  messages << { type: type.to_s, message: format_markdown(message) }
end

#error_messages?(message_list: messages) ⇒ Boolean

Returns true if an error message was logged to the runnable

Parameters:

  • message_list (Array) (defaults to: messages)

    (optional) list of messages to check for error, if not provided, the runnable’s current list of messages will be checked

Returns:

  • (Boolean)


19
20
21
# File 'lib/inferno/dsl/messages.rb', line 19

def error_messages?(message_list: messages)
  message_list.any? { |msg| msg[:type] == 'error' }
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)


45
46
47
48
49
50
51
52
53
54
# File 'lib/inferno/dsl/messages.rb', line 45

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

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


69
70
71
72
73
74
75
76
77
78
# File 'lib/inferno/dsl/messages.rb', line 69

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