class OnlyofficeTcmHelper::TcmHelper

Class for generate data for result by RSpec::Core::Example

Attributes

case_name[R]

@return [String] name of case(or name of result_set)

comment[R]

@return [String] is a comment for result, like a error, link to bug, etc

example[R]

@return [RSpec::Core::Example] example - is a returned object in “after” block

last_case[R]

@return [String] is a name last case, who result has generated

plan_name[R]

@return [String] is a name of plan

product_name[R]

@return [String] is a name of product

result_message[RW]

@return [Hash] is a result message.

status[RW]

@return [Symbol] one of status: passed, passed_2, failed, aborted, pending, service_unavailable, lpv

suite_name[R]

@return [String] is a name of suite(ore run)

Public Class Methods

new(params = {}) click to toggle source
# File lib/onlyoffice_tcm_helper.rb, line 35
def initialize(params = {})
  @product_name = params[:product_name]
  @plan_name = params[:plan_name]
  @suite_name = params[:suite_name]
end

Public Instance Methods

get_message_and_custom_fields(example) click to toggle source

Get message and custom fields from example @param [Object] example to get @return [String] json data

# File lib/onlyoffice_tcm_helper.rb, line 53
def get_message_and_custom_fields(example)
  custom_fields = {}
  custom_fields[:subdescriber] = [
    { title: 'elapsed', value: example_time_in_seconds(example) },
    { title: 'custom_host', value: Socket.gethostname }
  ]
  custom_fields[:describer] = [{ title: 'comment', value: @comment }]
  custom_fields.to_json
end
get_status_and_comment(example) click to toggle source

@param [RSpec::Core::Example] example - is a returned object in “after” block @return [Symbol] is a symbolic name of test status

# File lib/onlyoffice_tcm_helper.rb, line 65
def get_status_and_comment(example)
  @status = if result_is_failed?(example)
              comment = "\n#{example.exception.to_s
                                    .gsub('got:', "got:\n")
                                    .gsub('expected:', "expected:\n")
                                    .gsub('to return ', "to return:\n")}\n"\
                        "In line:\n#{RspecHelper.find_failed_line(example)}"
              @comment = comment
              :failed
            elsif example.pending?
              @comment = example.execution_result.pending_message
              :pending
            elsif result_is_passed?(example)
              @comment = "\nOk"
              :passed
            elsif result_is_passed2?(example)
              @comment = "\nPassed 2"
              :passed_2
            elsif result_is_service_unavailable?(example)
              @comment = "\n#{example.exception}"
              :service_unavailable
            elsif result_is_lpv?(example)
              @comment = "\n#{example.exception}"
              :lpv
            else
              @comment = "\n#{example.exception}"
              :aborted
            end
  @last_case = @case_name
end
parse(example) click to toggle source

@param [RSpec::Core::Example] example - is a returned object in “after” block @return [TcmHelper] is object

# File lib/onlyoffice_tcm_helper.rb, line 43
def parse(example)
  @case_name = example.metadata[:description]
  get_status_and_comment(example)
  @result_message = get_message_and_custom_fields(example)
  self
end
result_is_failed?(example) click to toggle source
# File lib/onlyoffice_tcm_helper.rb, line 104
def result_is_failed?(example)
  # return true if example.metadata[:execution_result].pending_fixed
  ['got:', 'expected:', 'to return'].map do |current_error|
    return true if example.exception.to_s.include?(current_error)
  end
  false
end
result_is_lpv?(example) click to toggle source
# File lib/onlyoffice_tcm_helper.rb, line 116
def result_is_lpv?(example)
  example.exception.to_s.include?('Limited program version')
end
result_is_passed2?(example) click to toggle source
# File lib/onlyoffice_tcm_helper.rb, line 100
def result_is_passed2?(example)
  example.exception.nil? && @last_case == example.description
end
result_is_passed?(example) click to toggle source
# File lib/onlyoffice_tcm_helper.rb, line 96
def result_is_passed?(example)
  example.exception.nil? && @last_case != example.description
end
result_is_service_unavailable?(example) click to toggle source
# File lib/onlyoffice_tcm_helper.rb, line 112
def result_is_service_unavailable?(example)
  example.exception.to_s.include?('Service Unavailable')
end