class OnlyofficeTcmHelper::TcmHelper
Class for generate data for result by RSpec::Core::Example
Attributes
@return [String] name of case(or name of result_set)
@return [String] is a comment for result, like a error, link to bug, etc
@return [RSpec::Core::Example] example - is a returned object in “after” block
@return [String] is a name last case, who result has generated
@return [String] is a name of plan
@return [String] is a name of product
@return [Hash] is a result message.
@return [Symbol] one of status: passed, passed_2, failed, aborted, pending, service_unavailable, lpv
@return [String] is a name of suite(ore run)
Public Class Methods
# 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 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
@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
@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
# 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
# File lib/onlyoffice_tcm_helper.rb, line 116 def result_is_lpv?(example) example.exception.to_s.include?('Limited program version') end
# File lib/onlyoffice_tcm_helper.rb, line 100 def result_is_passed2?(example) example.exception.nil? && @last_case == example.description end
# File lib/onlyoffice_tcm_helper.rb, line 96 def result_is_passed?(example) example.exception.nil? && @last_case != example.description end