Class: OnlyofficeTcmHelper::TcmHelper

Inherits:
Object
  • Object
show all
Includes:
PendingHelper, RspecHelper, TimeHelper
Defined in:
lib/onlyoffice_tcm_helper.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RspecHelper

find_dirty_line, find_failed_line

Methods included from TimeHelper

#example_time_in_seconds

Methods included from PendingHelper

#handle_pending, #passed_pending_message, #pending_passed?, #pending_status

Constructor Details

#initialize(params = {}) ⇒ TcmHelper

Returns a new instance of TcmHelper.



37
38
39
40
41
# File 'lib/onlyoffice_tcm_helper.rb', line 37

def initialize(params = {})
  @product_name = params[:product_name]
  @plan_name = params[:plan_name]
  @suite_name = params[:suite_name]
end

Instance Attribute Details

#case_nameString (readonly)

Returns name of case(or name of result_set).

Returns:

  • (String)

    name of case(or name of result_set)



21
22
23
# File 'lib/onlyoffice_tcm_helper.rb', line 21

def case_name
  @case_name
end

#commentString (readonly)

Returns is a comment for result, like a error, link to bug, etc.

Returns:

  • (String)

    is a comment for result, like a error, link to bug, etc



25
26
27
# File 'lib/onlyoffice_tcm_helper.rb', line 25

def comment
  @comment
end

#exampleRSpec::Core::Example (readonly)

Returns example - is a returned object in “after” block.

Returns:

  • (RSpec::Core::Example)

    example - is a returned object in “after” block



23
24
25
# File 'lib/onlyoffice_tcm_helper.rb', line 23

def example
  @example
end

#last_caseString (readonly)

Returns is a name last case, who result has generated.

Returns:

  • (String)

    is a name last case, who result has generated



33
34
35
# File 'lib/onlyoffice_tcm_helper.rb', line 33

def last_case
  @last_case
end

#plan_nameString (readonly)

Returns is a name of plan.

Returns:

  • (String)

    is a name of plan



29
30
31
# File 'lib/onlyoffice_tcm_helper.rb', line 29

def plan_name
  @plan_name
end

#product_nameString (readonly)

Returns is a name of product.

Returns:

  • (String)

    is a name of product



27
28
29
# File 'lib/onlyoffice_tcm_helper.rb', line 27

def product_name
  @product_name
end

#result_messageHash

Returns is a result message.

Returns:

  • (Hash)

    is a result message.



35
36
37
# File 'lib/onlyoffice_tcm_helper.rb', line 35

def result_message
  @result_message
end

#statusSymbol

Returns one of status: passed, passed_2, failed, aborted, pending, service_unavailable, lpv.

Returns:

  • (Symbol)

    one of status: passed, passed_2, failed, aborted, pending, service_unavailable, lpv



19
20
21
# File 'lib/onlyoffice_tcm_helper.rb', line 19

def status
  @status
end

#suite_nameString (readonly)

Returns is a name of suite(ore run).

Returns:

  • (String)

    is a name of suite(ore run)



31
32
33
# File 'lib/onlyoffice_tcm_helper.rb', line 31

def suite_name
  @suite_name
end

Instance Method Details

#get_message_and_custom_fields(example) ⇒ String

Get message and custom fields from example

Parameters:

  • example (Object)

    to get

Returns:

  • (String)

    json data



55
56
57
58
59
60
61
62
63
# File 'lib/onlyoffice_tcm_helper.rb', line 55

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) ⇒ Symbol

Returns is a symbolic name of test status.

Parameters:

  • example (RSpec::Core::Example)
    • is a returned object in “after” block

Returns:

  • (Symbol)

    is a symbolic name of test status



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/onlyoffice_tcm_helper.rb', line 67

def get_status_and_comment(example)
  @status = if result_is_failed?(example)
              @comment = form_failed_comment(example)
              :failed
            elsif example.pending?
              handle_pending(example)
            elsif result_is_passed?(example)
              @comment = "\nOk"
              :passed
            elsif result_is_passed2?(example)
              @comment = "\nPassed 2"
              :passed_2
            else
              handle_other_status(example)
            end
  @last_case = @case_name
end

#parse(example) ⇒ TcmHelper

Returns is object.

Parameters:

  • example (RSpec::Core::Example)
    • is a returned object in “after” block

Returns:



45
46
47
48
49
50
# File 'lib/onlyoffice_tcm_helper.rb', line 45

def parse(example)
  @case_name = example.[:description]
  get_status_and_comment(example)
  @result_message = get_message_and_custom_fields(example)
  self
end

#result_is_failed?(example) ⇒ Boolean

Returns:

  • (Boolean)


93
94
95
96
97
98
99
# File 'lib/onlyoffice_tcm_helper.rb', line 93

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) ⇒ Boolean

Returns:

  • (Boolean)


105
106
107
# File 'lib/onlyoffice_tcm_helper.rb', line 105

def result_is_lpv?(example)
  example.exception.to_s.include?('Limited program version')
end

#result_is_passed2?(example) ⇒ Boolean

Returns:

  • (Boolean)


89
90
91
# File 'lib/onlyoffice_tcm_helper.rb', line 89

def result_is_passed2?(example)
  example.exception.nil? && @last_case == example.description
end

#result_is_passed?(example) ⇒ Boolean

Returns:

  • (Boolean)


85
86
87
# File 'lib/onlyoffice_tcm_helper.rb', line 85

def result_is_passed?(example)
  example.exception.nil? && @last_case != example.description
end

#result_is_service_unavailable?(example) ⇒ Boolean

Returns:

  • (Boolean)


101
102
103
# File 'lib/onlyoffice_tcm_helper.rb', line 101

def result_is_service_unavailable?(example)
  example.exception.to_s.include?('Service Unavailable')
end