Class: QAT::Reporter::Formatter::TimeMeasurements

Inherits:
Object
  • Object
show all
Includes:
Cucumber::Formatter::Duration, Cucumber::Formatter::Io, Formatter::Helper, Formatter::Loggable, Logger
Defined in:
lib/qat/reporter/formatter/time_measurements.rb

Overview

Namespace for Time Measurements formatter

Since:

  • 7.0.0

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ TimeMeasurements

Returns a new instance of TimeMeasurements.

Since:

  • 7.0.0



27
28
29
30
31
32
33
34
35
36
# File 'lib/qat/reporter/formatter/time_measurements.rb', line 27

def initialize(config)
  @config         = config
  @io             = ensure_io(config.out_stream, config.error_stream)
  @ast_lookup     = ::Cucumber::Formatter::AstLookup.new(config)
  @feature_hashes = []
  config.on_event :test_case_started, &method(:on_test_case_started)
  config.on_event :test_case_finished, &method(:on_test_case_finished)
  config.on_event :test_run_finished, &method(:on_test_run_finished)
  @json_content = []
end

Instance Method Details

#feature_bodyObject

Since:

  • 7.0.0



145
146
147
148
149
150
151
152
# File 'lib/qat/reporter/formatter/time_measurements.rb', line 145

def feature_body
  @current_feature_info = {
    feature:   @feature_hash[:name],
    tags:      @feature_hash[:tags],
    timestamp: @current_feature_timestamp,
    scenarios: []
  }
end

#on_test_case_finished(event) ⇒ Object

Since:

  • 7.0.0



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/qat/reporter/formatter/time_measurements.rb', line 60

def on_test_case_finished event
  return if @config.dry_run?
  _test_case, result = *event.attributes
  @current_feature   = nil
  @current_feature_info[:scenarios] << @current_scenario_info

  test_run_id = QAT[:current_test_run_id]
  measurements = QAT::Reporter::Times.get_measures rescue []

  test_status = if result.passed?
                  if QAT::Reporter.const_defined?('Times')
                    QAT::Reporter::Times.test_sla_status
                  else
                    "passed"
                  end
                elsif result.failed?
                  "failed"
                else
                  "not_runned"
                end

  test_run_info = {
    id:           test_run_id,
    test_status:  test_status,
    timestamp:    QAT[:test_start_timestamp]&.strftime("%FT%T%z"),
    measurements: []
  }

  measurements.each do |id, measure|
    if id
      minutes, seconds = measure[:duration].divmod(60)
      test_run_info[:measurements] << {
        id:        id,
        name:      measure[:name],
        timestamp: measure[:start].strftime("%FT%T%z"),
        time:      {
          secs:  measure[:duration],
          human: "#{minutes}m #{'%02.0f' % seconds}s"
        },
        sla:       measure[:sla]
      }
    end
  end

  @current_scenario_info[:test_runs] << test_run_info
end

#on_test_case_started(event) ⇒ Object

Since:

  • 7.0.0



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/qat/reporter/formatter/time_measurements.rb', line 39

def on_test_case_started event
  return if @config.dry_run?
  @row_number = nil
  test_case   = event.test_case
  build(test_case, @ast_lookup)

  if @current_feature_info.nil?
    @current_feature_timestamp = Time.now.strftime("%FT%T%z")
    feature_body
  elsif @current_feature_info.values.include?(@feature_hash[:name])
  else
    @current_feature_timestamp = Time.now.strftime("%FT%T%z")
    process_scenarios
    feature_body
  end

  @current_scenario        = @scenario
  @current_scenario[:tags] = @current_scenario[:tags] - @feature_hash[:tags] if @feature_hash[:tags]
  scenario_body
end

#on_test_run_finished(event) ⇒ Object

Since:

  • 7.0.0



107
108
109
110
111
# File 'lib/qat/reporter/formatter/time_measurements.rb', line 107

def on_test_run_finished event
  return if @config.dry_run?
  process_scenarios
  @io.puts(JSON.pretty_generate(@json_content))
end

#process_scenariosObject

Since:

  • 7.0.0



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/qat/reporter/formatter/time_measurements.rb', line 114

def process_scenarios
  @indexes           = []
  @indexes_test_runs = []
  @scenarios         = @current_feature_info[:scenarios]

  @scenarios.each_with_index do |key, value|
    test_run = key[:test_runs]
    #Verifies if exist measures in a test_run
    test_run.each_with_index do |key, value|
      if key[:measurements].empty?
        @indexes << value
      end
    end
    #Deletes the empty measures
    @indexes.reverse!.each do |v|
      test_run.delete_at(v)
    end
    #Verifies if exist test_runs in a scenarios
    if key[:test_runs].empty?
      @indexes_test_runs << value
    end
  end
  #Delete empty test runs:
  @indexes_test_runs.reverse!.each do |v|
    @current_feature_info[:scenarios].delete_at(v)
  end

  @json_content << @current_feature_info unless @scenarios.empty?
end

#scenario_bodyObject

Since:

  • 7.0.0



154
155
156
157
158
159
160
161
# File 'lib/qat/reporter/formatter/time_measurements.rb', line 154

def scenario_body
  @current_scenario_info = {
    name:      @current_scenario[:name],
    tags:      @current_scenario[:tags],
    timestamp: Time.now.strftime("%FT%T%z"),
    test_runs: []
  }
end