Class: QAT::Formatter::TestIds

Inherits:
Object
  • Object
show all
Includes:
Cucumber::Formatter::Io, Helper
Defined in:
lib/qat/formatter/test_ids.rb

Overview

Formatter to get duplicate test ids and get scenarios untagged

Since:

  • 0.1.0

Instance Method Summary collapse

Methods included from Helper

#assign_print_feature, #on_test_case_finished, #on_test_step_finished, #on_test_step_started, #print_assign_step, #print_scenario_results, #print_scenario_start

Methods included from UtilityFuction

#background, #calculate_row_number, #create_feature_hash, #features?, #get_example_values, #get_lines_from_scenario

Methods included from Builder

#add_values_to_examples, #build, #create_id_from_scenario_source, #feature, #get_scenario_tags, #scenario

Constructor Details

#initialize(config) ⇒ TestIds

Returns a new instance of TestIds.

Since:

  • 0.1.0



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/qat/formatter/test_ids.rb', line 12

def initialize(config)
  @config             = config
  @no_test_id         = {}
  @max_test_id        = 0
  @duplicate_test_ids = {}
  @test_id_mapping    = {}
  @io                 = ensure_io(config.out_stream, config.error_stream)
  @ast_lookup         = ::Cucumber::Formatter::AstLookup.new(@config)
  config.on_event :test_case_started, &method(:on_test_case_started)
  config.on_event :test_run_finished, &method(:on_test_run_finished)

end

Instance Method Details

#on_test_case_started(event) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.1.0



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

def on_test_case_started event
  @feature_hashes     = []
  @tags               = []
  @scenario_tags      = []
  @examples_values = []
  build(event.test_case, @ast_lookup)
  @current_feature = @feature_hash
  scenario_name
end

#on_test_run_finished(_event) ⇒ Object

Since:

  • 0.1.0



37
38
39
40
# File 'lib/qat/formatter/test_ids.rb', line 37

def on_test_run_finished(_event)
  publish_result
  @io.flush
end

#scenario_nameObject

Since:

  • 0.1.0



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/qat/formatter/test_ids.rb', line 42

def scenario_name
 path = "#{@current_feature[:uri]}:#{@scenario[:line]}"
 scenario_tags= @scenario[:tags]
  if scenario_tags.any? { |tag| tag.match(/@test#(\d+)/) }
    id           = scenario_tags.map { |tag| tag.match(/@test#(\d+)/) }.compact.first.captures.first.to_i
    @max_test_id = id if id > @max_test_id

    test_id_info = { name: @scenario[:name],
                     path:  path}

    if @test_id_mapping[id]
      if @duplicate_test_ids[id]
        @duplicate_test_ids[id].find do |dup|
          @exist = true if dup[:path]== test_id_info[:path]
        end
        @duplicate_test_ids[id] << test_id_info unless @exist
      else
        @duplicate_test_ids[id] = [@test_id_mapping[id], test_id_info] unless @test_id_mapping[id][:path] == test_id_info[:path]
      end
    else
      @test_id_mapping[id] = test_id_info
    end
  else
    @no_test_id[@scenario[:name]] = path unless scenario_tags.include?('@dummy_test')
  end
  @scenario[:tags] = []
end