qat-cucumber 6.0.3 → 7.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f21956528249e26b4038f4f8656378941eec425a80be37ab34edb6b83f919984
4
- data.tar.gz: 27e3816c26c73453fe03a4bb56744da087699236c4c4236508b6ed7a0c8c9723
3
+ metadata.gz: 0c2d9c16ada4ae99664285b5387929d4292fe8414e21a8aae66857f094afc2f2
4
+ data.tar.gz: c957475c29c8977726b1b79b1e9714323aff2e8ee0e7f12e4bf81922527dfe83
5
5
  SHA512:
6
- metadata.gz: 70b0ee8878eede7b33858d62923379bbbc6c30ec8eea3036361c94b01e72c143c29457a31cd42389d4fa8068d3eb3d271b6b23154d536469648566b0961fa179
7
- data.tar.gz: a36f92600d932fbabfac421dc181cb2d69e05f1ec831432bc229322540518a93be4f40b746784c5f3f255dee0d15a2562ea57004410d2d81b087325a071f0c4f
6
+ metadata.gz: 21d90b8f0ad2711a838cacbffdcaf63791f316320bfa0012cb1bef9fe394d96a23f2648c7b1957941b8c674b7e3c360be4761cb2b3c85cda870bb1d7a35ba7dc
7
+ data.tar.gz: 17d16d5f040bfc49dbbab89ff25414d5dfe603f238d10a65852ee729c897d98909b0a70148a53ec5fa3730ac85186ba9318be454f0a36dd33c1aa1b6e3c13375
@@ -1,48 +1,48 @@
1
1
  require 'cucumber/formatter/html'
2
2
 
3
- #Extension to the cucumber module adding the embed video options
4
- module Cucumber
5
- #Extension to the formatter module adding the embed video options
6
- module Formatter
7
- #Extension to the html class adding the embed video options
8
- class Html
9
- #Method embed that also contains options to embed video case the extension is met
10
- def embed(src, mime_type, label)
11
- case (mime_type)
12
- when /^image\/(png|gif|jpg|jpeg)/
13
- unless File.file?(src) or src =~ /^data:image\/(png|gif|jpg|jpeg);base64,/
14
- type = mime_type =~ /;base[0-9]+$/ ? mime_type : mime_type + ";base64"
15
- src = "data:" + type + "," + src
16
- end
17
- embed_image(src, label)
18
- when /^text\/plain/
19
- embed_text(src, label)
20
- when /^video\/\w+/
21
- embed_video(src,mime_type, label)
22
- end
23
- end
24
-
25
- #Method to embed the video in the HTML Report
26
- def embed_video(src,mime_type, label)
27
- @video_id ||= 0
28
-
29
- if @io.respond_to?(:path) and File.file?(src)
30
- out_dir = Pathname.new(File.dirname(File.absolute_path(@io.path)))
31
- src = Pathname.new(File.absolute_path(src)).relative_path_from(out_dir)
32
- end
33
-
34
- @builder.span(:class => 'embed') do |pre|
35
- pre << %{
36
- <a href="" onclick="video=document.getElementById('video_div_#{@video_id}'); video.style.display = (video.style.display == 'none' ? 'block' : 'none');return false"><br>#{label}</a><br>&nbsp;
37
- <div id="video_div_#{@video_id}" style="display: none">
38
- <video id="video_#{@video_id}" autostart="0" width="800" height="600" controls> <source src="#{src}" type="#{mime_type}" ></video><br>
39
- <a href="#{src}" download="#{src}">Download Video</a>
40
- </div>}
41
- end
42
-
43
- @video_id += 1
44
- end
45
- end
46
- end
47
- end
3
+ # #Extension to the cucumber module adding the embed video options
4
+ # module Cucumber
5
+ # #Extension to the formatter module adding the embed video options
6
+ # module Formatter
7
+ # #Extension to the html class adding the embed video options
8
+ # class Html
9
+ # #Method embed that also contains options to embed video case the extension is met
10
+ # def embed(src, mime_type, label)
11
+ # case (mime_type)
12
+ # when /^image\/(png|gif|jpg|jpeg)/
13
+ # unless File.file?(src) or src =~ /^data:image\/(png|gif|jpg|jpeg);base64,/
14
+ # type = mime_type =~ /;base[0-9]+$/ ? mime_type : mime_type + ";base64"
15
+ # src = "data:" + type + "," + src
16
+ # end
17
+ # embed_image(src, label)
18
+ # when /^text\/plain/
19
+ # embed_text(src, label)
20
+ # when /^video\/\w+/
21
+ # embed_video(src,mime_type, label)
22
+ # end
23
+ # end
24
+ #
25
+ # #Method to embed the video in the HTML Report
26
+ # def embed_video(src,mime_type, label)
27
+ # @video_id ||= 0
28
+ #
29
+ # if @io.respond_to?(:path) and File.file?(src)
30
+ # out_dir = Pathname.new(File.dirname(File.absolute_path(@io.path)))
31
+ # src = Pathname.new(File.absolute_path(src)).relative_path_from(out_dir)
32
+ # end
33
+ #
34
+ # @builder.span(:class => 'embed') do |pre|
35
+ # pre << %{
36
+ # <a href="" onclick="video=document.getElementById('video_div_#{@video_id}'); video.style.display = (video.style.display == 'none' ? 'block' : 'none');return false"><br>#{label}</a><br>&nbsp;
37
+ # <div id="video_div_#{@video_id}" style="display: none">
38
+ # <video id="video_#{@video_id}" autostart="0" width="800" height="600" controls> <source src="#{src}" type="#{mime_type}" ></video><br>
39
+ # <a href="#{src}" download="#{src}">Download Video</a>
40
+ # </div>}
41
+ # end
42
+ #
43
+ # @video_id += 1
44
+ # end
45
+ # end
46
+ # end
47
+ # end
48
48
 
@@ -1,57 +1,57 @@
1
1
  require 'cucumber/formatter/junit'
2
2
 
3
- module Cucumber
4
- module Formatter
5
- # The formatter used for <tt>--format junit</tt>
6
- class Junit
3
+ # module Cucumber
4
+ # module Formatter
5
+ # # The formatter used for <tt>--format junit</tt>
6
+ # class Junit
7
7
 
8
- #Method to parse time in testsuite elements
9
- def end_feature(feature_data)
10
- @testsuite = Builder::XmlMarkup.new(:indent => 2)
11
- @testsuite.instruct!
12
- @testsuite.testsuite(
13
- :failures => feature_data[:failures],
14
- :errors => feature_data[:errors],
15
- :skipped => feature_data[:skipped],
16
- :tests => feature_data[:tests],
17
- :time => "%.3f" % feature_data[:time],
18
- :name => feature_data[:feature].name) do
19
- @testsuite << feature_data[:builder].target!
20
- end
21
-
22
- write_file(feature_result_filename(feature_data[:feature].file), @testsuite.target!)
23
- end
24
-
25
- #Method to parse time in testcase elements
26
- def build_testcase(result, scenario_designation, output)
27
- duration = ResultBuilder.new(result).test_case_duration
28
- @current_feature_data[:time] += duration
29
- classname = @current_feature_data[:feature].name
30
- name = scenario_designation
31
-
32
- @current_feature_data[:builder].testcase(:classname => classname, :name => name, :time => "%.3f" % duration) do
33
- if !result.passed? && result.ok?(@config.strict?)
34
- @current_feature_data[:builder].skipped
35
- @current_feature_data[:skipped] += 1
36
- elsif !result.passed?
37
- status = result.to_sym
38
- exception = get_backtrace_object(result)
39
- @current_feature_data[:builder].failure(:message => "#{status} #{name}", :type => status) do
40
- @current_feature_data[:builder].cdata! output
41
- @current_feature_data[:builder].cdata!(format_exception(exception)) if exception
42
- end
43
- @current_feature_data[:failures] += 1
44
- end
45
- @current_feature_data[:builder].tag!('system-out') do
46
- @current_feature_data[:builder].cdata! strip_control_chars(@interceptedout.buffer.join)
47
- end
48
- @current_feature_data[:builder].tag!('system-err') do
49
- @current_feature_data[:builder].cdata! strip_control_chars(@interceptederr.buffer.join)
50
- end
51
- end
52
- @current_feature_data[:tests] += 1
53
- end
54
- end
55
- end
56
- end
8
+ # #Method to parse time in testsuite elements
9
+ # def end_feature(feature_data)
10
+ # @testsuite = Builder::XmlMarkup.new(:indent => 2)
11
+ # @testsuite.instruct!
12
+ # @testsuite.testsuite(
13
+ # :failures => feature_data[:failures],
14
+ # :errors => feature_data[:errors],
15
+ # :skipped => feature_data[:skipped],
16
+ # :tests => feature_data[:tests],
17
+ # :time => "%.3f" % feature_data[:time],
18
+ # :name => feature_data[:feature].name) do
19
+ # @testsuite << feature_data[:builder].target!
20
+ # end
21
+ #
22
+ # write_file(feature_result_filename(feature_data[:feature].file), @testsuite.target!)
23
+ # end
24
+ #
25
+ # #Method to parse time in testcase elements
26
+ # def build_testcase(result, scenario_designation, output)
27
+ # duration = ResultBuilder.new(result).test_case_duration
28
+ # @current_feature_data[:time] += duration
29
+ # classname = @current_feature_data[:feature].name
30
+ # name = scenario_designation
31
+ #
32
+ # @current_feature_data[:builder].testcase(:classname => classname, :name => name, :time => "%.3f" % duration) do
33
+ # if !result.passed? && result.ok?(@config.strict)
34
+ # @current_feature_data[:builder].skipped
35
+ # @current_feature_data[:skipped] += 1
36
+ # elsif !result.passed?
37
+ # status = result.to_sym
38
+ # exception = get_backtrace_object(result)
39
+ # @current_feature_data[:builder].failure(:message => "#{status} #{name}", :type => status) do
40
+ # @current_feature_data[:builder].cdata! output
41
+ # @current_feature_data[:builder].cdata!(format_exception(exception)) if exception
42
+ # end
43
+ # @current_feature_data[:failures] += 1
44
+ # end
45
+ # @current_feature_data[:builder].tag!('system-out') do
46
+ # @current_feature_data[:builder].cdata! strip_control_chars(@interceptedout.buffer_string)
47
+ # end
48
+ # @current_feature_data[:builder].tag!('system-err') do
49
+ # @current_feature_data[:builder].cdata! strip_control_chars(@interceptederr.buffer_string)
50
+ # end
51
+ # end
52
+ # @current_feature_data[:tests] += 1
53
+ # end
54
+ # end
55
+ # end
56
+ # end
57
57
 
@@ -1,16 +1,16 @@
1
- require 'cucumber/core/test/result'
2
-
3
- #Patch for Cucumber::Core::Test::Result::Unknown to implement methods used by the formatters
4
- #@since 1.1.0
5
- class Cucumber::Core::Test::Result::Unknown
6
-
7
- #Dummy function
8
- def with_appended_backtrace(_)
9
- ''
10
- end
11
-
12
- #Dummy function
13
- def with_filtered_backtrace(_)
14
- ''
15
- end
16
- end
1
+ # require 'cucumber/core/test/result'
2
+ #
3
+ # #Patch for Cucumber::Core::Test::Result::Unknown to implement methods used by the formatters
4
+ # #@since 1.1.0
5
+ # class Cucumber::Core::Test::Result::Unknown
6
+ #
7
+ # #Dummy function
8
+ # def with_appended_backtrace(_)
9
+ # ''
10
+ # end
11
+ #
12
+ # #Dummy function
13
+ # def with_filtered_backtrace(_)
14
+ # ''
15
+ # end
16
+ # end
@@ -2,6 +2,7 @@
2
2
  require 'cucumber'
3
3
  require 'qat/logger'
4
4
 
5
+
5
6
  module QAT
6
7
  module Cucumber
7
8
  #Methods to execute with Cucumber Hooks and at_exit.
@@ -24,7 +25,7 @@ module QAT
24
25
 
25
26
  private
26
27
  def test_id(scenario)
27
- outline_id = get_outline_id(scenario)
28
+ # outline_id = get_outline_id(scenario)
28
29
 
29
30
  tags = scenario_tags(scenario)
30
31
  tag = tags.select { |tag| tag.match /^\@test\#/ }.first
@@ -35,39 +36,40 @@ module QAT
35
36
  'test_0'
36
37
  end
37
38
 
38
- "#{test_id}#{outline_id}"
39
- end
40
-
41
- def get_outline_id(scenario)
42
- if scenario.is_a? ::Cucumber::RunningTestCase::ScenarioOutlineExample
43
- test_case = scenario.instance_exec { @test_case }
44
- test_case_source = test_case.source
45
-
46
- tables = get_example_tables(test_case_source)
47
- table_lines = get_examples_size(tables)
48
- table_num = current_outline_index(tables, test_case_source)
49
- previous_outlines = count_previous_outlines(table_lines, table_num)
50
- "_#{previous_outlines + test_case_source[3].number}"
51
- else
52
- nil
53
- end
54
- end
55
-
56
- def get_example_tables(test_case_source)
57
- test_case_source[1].instance_exec { @examples_tables }
39
+ #"#{test_id}#{outline_id}"
40
+ "#{test_id}"
58
41
  end
59
42
 
60
- def get_examples_size(tables)
61
- tables.each.map { |table| table.example_rows.size }
62
- end
63
-
64
- def current_outline_index(tables, test_case_source)
65
- tables.index test_case_source[2]
66
- end
67
-
68
- def count_previous_outlines(table_lines, table_num)
69
- table_lines[0...table_num].inject(0) { |sum, lines| sum += lines; sum }
70
- end
43
+ # def get_outline_id(scenario)
44
+ # if scenario.is_a? ::Cucumber::RunningTestCase::ScenarioOutlineExample
45
+ # test_case = scenario.instance_exec { @test_case }
46
+ # test_case_source = test_case.source
47
+ #
48
+ # tables = get_example_tables(test_case_source)
49
+ # table_lines = get_examples_size(tables)
50
+ # table_num = current_outline_index(tables, test_case_source)
51
+ # previous_outlines = count_previous_outlines(table_lines, table_num)
52
+ # "_#{previous_outlines + test_case_source[3].number}"
53
+ # else
54
+ # nil
55
+ # end
56
+ # end
57
+ #
58
+ # def get_example_tables(test_case_source)
59
+ # test_case_source[1].instance_exec { @examples_tables }
60
+ # end
61
+ #
62
+ # def get_examples_size(tables)
63
+ # tables.each.map { |table| table.example_rows.size }
64
+ # end
65
+ #
66
+ # def current_outline_index(tables, test_case_source)
67
+ # tables.index test_case_source[2]
68
+ # end
69
+ #
70
+ # def count_previous_outlines(table_lines, table_num)
71
+ # table_lines[0...table_num].inject(0) { |sum, lines| sum += lines; sum }
72
+ # end
71
73
 
72
74
  extend self
73
75
  end
@@ -10,6 +10,6 @@ module QAT
10
10
  #@since 0.1.0
11
11
  module Cucumber
12
12
  # Represents QAT's version
13
- VERSION = '6.0.3'
13
+ VERSION = '7.0.0'
14
14
  end
15
15
  end
@@ -0,0 +1,86 @@
1
+ require_relative 'utility_function'
2
+
3
+ module QAT
4
+ module Formatter
5
+ # Helper for Formatters , most of the main methods are done to reduce code duplication
6
+ module Builder
7
+ include QAT::Formatter::UtilityFuction
8
+
9
+
10
+ def build (test_case, ast_lookup)
11
+ @background_hash = nil
12
+ uri = test_case.location.file
13
+ feature = ast_lookup.gherkin_document(uri).feature
14
+ feature(feature, uri)
15
+ background = feature.children.first.background
16
+ background(background) if background
17
+ scenario(ast_lookup.scenario_source(test_case), test_case)
18
+ end
19
+
20
+ def feature (feature, uri)
21
+ feature_tags = feature.tags
22
+ create_feature_hash feature, uri
23
+ return if feature_tags.empty?
24
+ tags_array = []
25
+ feature_tags.each { |tag| tags_array << tag.name }
26
+ @feature_hash[:tags] = tags_array
27
+ end
28
+
29
+ def scenario(scenario_source, test_case)
30
+ scenario = scenario_source.type == :Scenario ? scenario_source.scenario : scenario_source.scenario_outline
31
+ @scenario = {
32
+ id: "#{@feature_hash[:id]};#{create_id_from_scenario_source(scenario_source)}",
33
+ keyword: scenario.keyword,
34
+ name: test_case.name,
35
+ description: scenario.description || '',
36
+ line: get_lines_from_scenario(scenario_source, test_case),
37
+ type: 'scenario'
38
+ }
39
+
40
+ get_scenario_tags test_case.tags
41
+ end
42
+
43
+ def get_scenario_tags tags
44
+ if tags.empty?
45
+ @scenario[:tags] = []
46
+ else
47
+ tags_array = []
48
+
49
+ tags.each { |tag|
50
+ name = tag.name
51
+ if @test_id_tags
52
+ tags_array << name unless name.match(/@test#(\d+)/)
53
+ else
54
+ tags_array << name
55
+ end
56
+ }
57
+
58
+ @scenario[:tags] = tags_array
59
+ end
60
+ end
61
+
62
+
63
+ def create_id_from_scenario_source(scenario_source)
64
+ if scenario_source.type == :Scenario
65
+ @examples_values = nil
66
+ scenario_source.scenario.name
67
+ else
68
+ @examples_values = []
69
+ scenario_outline_name = scenario_source.scenario_outline.name
70
+ examples_name = scenario_source.examples.name
71
+ get_example_values scenario_source
72
+ @row_number = calculate_row_number(scenario_source)
73
+ "#{scenario_outline_name};#{examples_name};#{@row_number}"
74
+ end
75
+ end
76
+
77
+
78
+ def add_values_to_examples(cells)
79
+ @examples_values = cells.map do |data|
80
+ data[:value].to_s
81
+ end
82
+ end
83
+
84
+ end
85
+ end
86
+ end
@@ -1,8 +1,11 @@
1
1
  require 'fileutils'
2
2
  require 'cucumber/formatter/console'
3
3
  require 'cucumber/formatter/io'
4
+ require 'cucumber/formatter/ast_lookup'
4
5
  require 'cucumber/gherkin/formatter/escaping'
6
+ require 'cucumber/deprecate'
5
7
  require 'qat/logger'
8
+ require_relative 'helper'
6
9
  require_relative 'loggable'
7
10
 
8
11
  module QAT
@@ -15,88 +18,23 @@ module QAT
15
18
  include ::FileUtils
16
19
  include ::Cucumber::Formatter::Io
17
20
  include ::Cucumber::Gherkin::Formatter::Escaping
21
+ include ::Cucumber::Formatter
18
22
  include QAT::Formatter::Loggable
19
23
  include QAT::Logger
20
-
21
- #@api private
22
- def initialize(_, path_or_io, options)
23
- @options = options
24
-
25
- check_outputter path_or_io unless options[:dry_run]
26
- end
27
-
28
- #@api private
29
- def before_test_case test_case
30
- return if @options[:dry_run]
31
-
32
- unless @current_feature
33
- @current_feature = test_case.source[0]
34
- log.info { "Running #{@current_feature.keyword}: \"#{@current_feature.name}\"" }
35
- mdc_before_feature! @current_feature.name
36
- end
37
-
38
- @current_scenario = test_case.source[1]
39
- end
40
-
41
- #@api private
42
- def after_feature *_
43
- return if @options[:dry_run]
44
-
45
- log.info { "Finished #{@current_feature.keyword}: \"#{@current_feature.name}\"" }
46
- @current_feature = nil
47
- mdc_after_feature!
48
- end
49
-
50
- #@api private
51
- def after_test_case step, result
52
- return if @options[:dry_run]
53
-
54
- log.error { result.exception } if result.failed?
55
-
56
- log.info { "Finished #{@current_scenario.keyword}: \"#{format_scenario_name step}\" - #{result.to_sym}\n" } if @current_scenario
57
- end
58
-
59
- #@api private
60
- def before_test_step step
61
- return if @options[:dry_run]
62
-
63
- begin_test_step step do |type|
64
- case type
65
- when :after_step
66
- log.info "Step Done!" if @step_running
67
- when :before_scenario
68
- before_test_case step unless @current_feature
69
- log.info { "Running #{@current_scenario.keyword}: \"#{format_scenario_name step}\"" }
70
- when :before_step
71
- log.info "Step Done!\n" if @step_running
72
- step_name = "#{step.source.last.keyword}#{step.name}"
73
- log.info { "Step \"#{step_name}\"" }
74
- mdc_add_step! step_name
75
- end
76
- end
24
+ include QAT::Formatter::Helper
25
+
26
+ def initialize(config)
27
+ @config = config
28
+ @io = ensure_io(config.out_stream, config.error_stream)
29
+ @ast_lookup = ::Cucumber::Formatter::AstLookup.new(config)
30
+ @feature_hashes = []
31
+ config.on_event :test_case_started, &method(:on_test_case_started)
32
+ config.on_event :test_case_finished, &method(:on_test_case_finished)
33
+ config.on_event :test_step_started, &method(:on_test_step_started)
34
+ config.on_event :test_step_finished, &method(:on_test_step_finished)
35
+ config.on_event :test_run_finished, &method(:on_test_run_finished)
77
36
  end
78
37
 
79
- #@api private
80
- def puts obj
81
- return if @options[:dry_run]
82
-
83
- log.debug { obj }
84
- end
85
-
86
- private
87
- def format_scenario_name step
88
- return '' unless @current_scenario
89
- outline_number, outline_example = nil, nil
90
- scenario_name = if @current_scenario.is_a? ::Cucumber::Core::Ast::ScenarioOutline
91
- outline_example = step.source[3].values
92
- outline_number = calculate_outline_id(step)
93
- "#{@current_scenario.name} ##{outline_number}"
94
- else
95
- @current_scenario.name
96
- end
97
- mdc_before_scenario! @current_scenario.name, tags_from_test_step(step), outline_number, outline_example
98
- return scenario_name
99
- end
100
38
  end
101
39
  end
102
40
  end
@@ -4,6 +4,8 @@ require 'cucumber/formatter/io'
4
4
  require 'cucumber/gherkin/formatter/escaping'
5
5
  require 'qat/logger'
6
6
  require_relative 'loggable'
7
+ require 'cucumber/core/gherkin/writer'
8
+ require_relative 'helper'
7
9
 
8
10
  module QAT
9
11
  module Formatter
@@ -14,71 +16,25 @@ module QAT
14
16
  include ::FileUtils
15
17
  include ::Cucumber::Formatter::Io
16
18
  include ::Cucumber::Gherkin::Formatter::Escaping
19
+ include ::Cucumber::Core::Gherkin::Writer
17
20
  include QAT::Formatter::Loggable
18
21
  include QAT::Logger
22
+ include QAT::Formatter::Helper
19
23
 
20
24
  #@api private
21
- def initialize(_, path_or_io, options)
22
- @options = options
23
-
24
- ensure_outputter path_or_io unless options[:dry_run]
25
- end
26
-
27
-
28
- #@api private
29
- def before_test_case test_case
30
- return if @options[:dry_run]
31
-
32
- unless @current_feature
33
- @current_feature = test_case.source[0]
34
- mdc_before_feature! @current_feature.name
35
- end
36
-
37
- @current_scenario = test_case.source[1]
38
- end
39
-
40
- #@api private
41
- def after_feature *_
42
- return if @options[:dry_run]
43
-
44
- @current_feature = nil
45
- mdc_after_feature!
46
- end
47
-
48
- #@api private
49
- def after_test_case step, passed
50
- return if @options[:dry_run]
51
-
52
- if passed.respond_to? :exception
53
- mdc_add_step! @step_name
54
- mdc_add_status_failed!
55
- log.error passed.exception
56
- end
57
- end
58
-
59
- #@api private
60
- def before_test_step step
61
- return if @options[:dry_run]
62
-
63
- begin_test_step step do |type|
64
- if type == :before_step
65
- @step_name = "#{step.source.last.keyword}#{step.name}"
66
- mdc_add_step! @step_name
67
- elsif :before_scenario
68
- outline_number, outline_example = nil, nil
69
- if @current_scenario.is_a? ::Cucumber::Core::Ast::ScenarioOutline
70
- outline_example = step.source[3].values
71
- outline_number = calculate_outline_id(step)
72
- end
73
- mdc_before_scenario! @current_scenario.name, tags_from_test_step(step), outline_number, outline_example
74
- end
75
- end
25
+ def initialize(config)
26
+ @config = config
27
+ @io = ensure_io(config.out_stream, config.error_stream)
28
+ ensure_outputter config.out_stream
29
+ @ast_lookup = ::Cucumber::Formatter::AstLookup.new(config)
30
+ @feature_hashes = []
31
+ config.on_event :test_case_started, &method(:on_test_case_started)
32
+ config.on_event :test_case_finished, &method(:on_test_case_finished)
33
+ config.on_event :test_step_started, &method(:on_test_step_started)
34
+ config.on_event :test_step_finished, &method(:on_test_step_finished)
35
+ config.on_event :test_run_finished, &method(:on_test_run_finished)
76
36
  end
77
37
 
78
- # #@api private
79
- # def exception e, _
80
- # log.error e
81
- # end
82
38
  end
83
39
  end
84
40
  end
@@ -0,0 +1,91 @@
1
+ require_relative 'builder'
2
+ require_relative 'utility_function'
3
+
4
+ module QAT
5
+ module Formatter
6
+ # Helper for Formatters , most of the main methods are done to reduce code duplication
7
+ module Helper
8
+ include QAT::Formatter::Builder
9
+ include QAT::Formatter::UtilityFuction
10
+
11
+
12
+
13
+ def on_test_case_started event
14
+ return if @config.dry_run?
15
+ @row_number = nil
16
+ test_case = event.test_case
17
+ build(test_case, @ast_lookup)
18
+ assign_print_feature unless @current_feature
19
+ @current_scenario = @scenario
20
+ scenario_name = @current_scenario[:name]
21
+ print_scenario_start @current_scenario[:keyword], scenario_name
22
+ mdc_before_scenario! scenario_name, @current_scenario[:tags], @row_number, @examples_values
23
+ end
24
+
25
+
26
+ def on_test_case_finished event
27
+ return if @config.dry_run?
28
+ _test_case, result = *event.attributes
29
+ @current_feature = nil
30
+ if result.failed?
31
+ mdc_add_step! @mdc_text
32
+ mdc_add_status_failed!
33
+ log.error { result.exception }
34
+ else
35
+ print_scenario_results @current_scenario[:keyword], @current_scenario[:name], result
36
+ end
37
+ end
38
+
39
+ def on_test_step_started(event)
40
+ return if @config.dry_run?
41
+ test_step = event.test_step
42
+ return if internal_hook?(test_step)
43
+ return if support_hook?(test_step)
44
+ step_source = @ast_lookup.step_source(test_step).step
45
+ print_assign_step test_step, step_source
46
+ end
47
+
48
+
49
+ def on_test_step_finished(event)
50
+ return if @config.dry_run?
51
+ test_step, result = *event.attributes
52
+ return if internal_hook?(test_step)
53
+ return if support_hook?(test_step)
54
+ log.info "Step Done!"
55
+ end
56
+
57
+ def on_test_run_finished _event
58
+ return if @config.dry_run?
59
+ print_scenario_results @feature_hash[:keyword], @feature_hash[:name]
60
+ mdc_after_feature!
61
+ end
62
+
63
+ def assign_print_feature
64
+ @current_feature = @feature_hash
65
+ feature_name = @current_feature[:name]
66
+ print_scenario_start @current_feature[:keyword], feature_name
67
+ mdc_before_feature! feature_name
68
+ end
69
+
70
+
71
+ def print_assign_step test_step, step_source
72
+ test_step_text = test_step.text
73
+ log.info { "Step \"#{test_step_text}\"" }
74
+ @mdc_text = "#{step_source.keyword}#{test_step_text}"
75
+ mdc_add_step! @mdc_text
76
+ end
77
+
78
+ def print_scenario_results keyword, name, result = nil
79
+ if result
80
+ log.info { "Finished #{keyword}: \"#{name}\" - #{result}\n" }
81
+ else
82
+ log.info { "Finished #{keyword}: \"#{name}\"" }
83
+ end
84
+ end
85
+
86
+ def print_scenario_start keyword, name
87
+ log.info { "Running #{keyword}: \"#{name}\"" }
88
+ end
89
+ end
90
+ end
91
+ end
@@ -33,13 +33,13 @@ module QAT
33
33
  #@since 0.1.0
34
34
  def begin_test_step step
35
35
  #World: step.location = /usr/local/rvm/gems/ruby-2.2.3/gems/cucumber-2.0.2/lib/cucumber/filters/prepare_world.rb:27
36
- # step.name = "Before hook"
36
+ # step.to_s = "Before hook"
37
37
 
38
38
  #Hooks: step.location = /home/mgomes/Projects/qat/src/qat/lib/qat/cucumber/hooks.rb:53
39
- # step.name = "Before hook"
39
+ # step.to_s = "Before hook"
40
40
 
41
41
  #Stepdef: step.location = features/formatter.feature:8
42
- # step.name = step name
42
+ # step.to_s = step name
43
43
 
44
44
  type = set_type(step)
45
45
 
@@ -66,7 +66,7 @@ module QAT
66
66
 
67
67
  def set_type(step)
68
68
  location = step.location.file.to_s
69
- step_name = step.name
69
+ step_name = step.to_s
70
70
 
71
71
  if step_name == "After hook"
72
72
  :after_step
@@ -1,46 +1,65 @@
1
1
  require 'cucumber/formatter/io'
2
2
  require 'json'
3
+ require_relative '../helper'
3
4
 
4
5
  module QAT
5
6
  module Formatter
6
7
  module Scenario
7
8
  class Name
8
9
  include Cucumber::Formatter::Io
10
+ include QAT::Formatter::Helper
9
11
 
10
- def initialize(runtime, path_or_io, options)
11
- @runtime = runtime
12
- @io = ensure_io(path_or_io)
13
- @to_file = (@io != $stdout)
14
- @options = options
15
- @scenarios = {}
16
- @repeated = {}
12
+ def initialize(config)
13
+ @config = config
14
+ @io = ensure_io(config.out_stream, config.error_stream)
15
+ # @to_file = (@io != $stdout)
16
+ @to_file = @io
17
+ @scenarios = {}
18
+ @repeated = {}
19
+ @ast_lookup = ::Cucumber::Formatter::AstLookup.new(config)
20
+ @feature_hashes = []
21
+ config.on_event :test_case_started, &method(:on_test_case_started)
22
+ config.on_event :test_run_finished, &method(:on_test_run_finished)
17
23
  end
18
24
 
19
- def scenario_name(keyword, name, file_colon_line, source_indent)
25
+
26
+ def on_test_case_started event
27
+ @examples_values = []
28
+ build(event.test_case, @ast_lookup)
29
+ @current_feature = @feature_hash
30
+ scenario_name
31
+ end
32
+
33
+ def scenario_name
20
34
  if @to_file
21
- if @scenarios.values.include?(name)
22
- @repeated[name] ||= []
23
- @repeated[name] << file_colon_line
35
+ if @scenarios.values.include?(@scenario[:name])
36
+ file_colon_line = "#{@current_feature[:uri]}:#{@scenario[:line]}"
37
+ unless @scenarios.keys.include?(file_colon_line)
38
+ @repeated[@scenario[:name]] ||= []
39
+ @repeated[@scenario[:name]] << "#{@current_feature[:uri]}:#{@scenario[:line]}"
40
+ end
24
41
  end
25
- @scenarios[file_colon_line] = name
42
+ file_colon_line = "#{@current_feature[:uri]}:#{@scenario[:line]}"
43
+ @scenarios[file_colon_line] = @scenario[:name]
26
44
  else
27
- puts "#{name}: #{file_colon_line}"
45
+ Kernel.puts "#{@scenario[:name]}: #{file_colon_line}"
28
46
  end
29
47
  end
30
48
 
31
- def after_features(features)
49
+ def on_test_run_finished(_event)
32
50
  if @to_file
33
51
  content = {
34
52
  scenarios: @scenarios,
35
53
  repeated: @repeated
36
54
  }
37
- @io.puts(content.to_json({
38
- indent: ' ',
39
- space: ' ',
40
- object_nl: "\n"
41
- }))
55
+ @io.write (JSON.pretty_generate(content))
56
+ @io.flush
42
57
  end
43
58
  end
59
+
60
+
61
+
62
+
44
63
  end
45
64
  end
46
65
  end
@@ -1,5 +1,6 @@
1
1
  require 'cucumber/formatter/io'
2
2
  require 'json'
3
+ require_relative 'helper'
3
4
 
4
5
  module QAT
5
6
  module Formatter
@@ -13,50 +14,47 @@ module QAT
13
14
  #
14
15
  class Tags
15
16
  include Cucumber::Formatter::Io
17
+ include QAT::Formatter::Helper
16
18
 
17
19
  #@api private
18
- def initialize(runtime, path_or_io, options)
19
- @io = ensure_io(path_or_io)
20
+ def initialize(config)
21
+ @config = config
22
+ @io = ensure_io(config.out_stream, config.error_stream)
20
23
  @tags = []
21
24
  @scenario_tags = []
22
25
  @total_scenarios = 0
23
26
  @total_scenarios_without_tags = 0
24
27
  @scenarios_without_tags = {}
25
- @options = options
28
+ @ast_lookup = ::Cucumber::Formatter::AstLookup.new(config)
29
+ @feature_hashes = []
30
+ config.on_event :test_case_started, &method(:on_test_case_started)
31
+ config.on_event :test_run_finished, &method(:on_test_run_finished)
26
32
  end
27
33
 
28
- #@api private
29
- def after_features(features)
30
- publish_result
31
- end
32
34
 
33
- #@api private
34
- def before_feature(feature)
35
+
36
+ def on_test_case_started event
35
37
  @feature_tags = []
36
- @in_scenarios = false
38
+ @examples_values = []
39
+ test_case = event.test_case
40
+ build(test_case, @ast_lookup)
41
+ @current_feature = @feature_hash
42
+ @test_id_tags = true
43
+ scenario_name
37
44
  end
38
45
 
39
- #@api private
40
- def tag_name(tag_name)
41
- if @in_scenarios
42
- @scenario_tags << tag_name unless tag_name.match(/@test#(\d+)/)
43
- else
44
- @feature_tags << tag_name
45
- end
46
+ def on_test_run_finished(_event)
47
+ publish_result
46
48
  end
47
49
 
48
- #@api private
49
- def after_tags(tags)
50
- @in_scenarios = true unless @in_scenarios
51
- end
52
50
 
53
51
  #@api private
54
- def scenario_name(keyword, name, file_colon_line, source_indent)
55
- scenario_tags = @scenario_tags + @feature_tags
56
- @tags += scenario_tags
52
+ def scenario_name
53
+ scenario_tags = @scenario[:tags] + @feature_hash[:tags] if @scenario[:tags] && @feature_hash[:tags] rescue nil
54
+ @tags += scenario_tags unless scenario_tags.nil?
57
55
  @total_scenarios += 1
58
- unless scenario_tags.any?
59
- @scenarios_without_tags[name] = file_colon_line
56
+ unless scenario_tags.try(:any?)
57
+ @scenarios_without_tags[@scenario[:name]] = "#{@current_feature[:uri]}:#{@scenario[:line]}"
60
58
  @total_scenarios_without_tags += 1
61
59
  end
62
60
  @scenario_tags = []
@@ -70,12 +68,11 @@ module QAT
70
68
  { unique: @tags.uniq.sort,
71
69
  total: @tags.size }
72
70
  }
73
- @io.puts(content.to_json({
74
- indent: ' ',
75
- space: ' ',
76
- object_nl: "\n"
77
- }))
71
+ @io.write (JSON.pretty_generate(content))
78
72
  end
73
+
74
+
75
+
79
76
  end
80
77
  end
81
78
  end
@@ -1,64 +1,74 @@
1
1
  require 'cucumber/formatter/io'
2
2
  require 'json'
3
+ require_relative 'helper'
3
4
 
4
5
  module QAT
5
6
  module Formatter
6
- class TestIds
7
+ # Formatter to get duplicate test ids and get scenarios untagged
8
+ class TestIds
7
9
  include Cucumber::Formatter::Io
10
+ include QAT::Formatter::Helper
8
11
 
9
- def initialize(runtime, path_or_io, options)
10
- @io = ensure_io(path_or_io)
11
- @tags = []
12
- @scenario_tags = []
12
+ def initialize(config)
13
+ @config = config
13
14
  @no_test_id = {}
14
15
  @max_test_id = 0
15
16
  @duplicate_test_ids = {}
16
17
  @test_id_mapping = {}
17
- @options = options
18
- end
18
+ @io = ensure_io(config.out_stream, config.error_stream)
19
+ @ast_lookup = ::Cucumber::Formatter::AstLookup.new(@config)
20
+ config.on_event :test_case_started, &method(:on_test_case_started)
21
+ config.on_event :test_run_finished, &method(:on_test_run_finished)
19
22
 
20
- def before_feature(feature)
21
- @in_scenarios = false
22
23
  end
23
24
 
24
- def tag_name(tag_name)
25
- @scenario_tags << tag_name if @in_scenarios
25
+
26
+ #@api private
27
+ def on_test_case_started event
28
+ @feature_hashes = []
29
+ @tags = []
30
+ @scenario_tags = []
31
+ @examples_values = []
32
+ build(event.test_case, @ast_lookup)
33
+ @current_feature = @feature_hash
34
+ scenario_name
26
35
  end
27
36
 
28
- def after_tags(tags)
29
- @in_scenarios = true unless @in_scenarios
37
+ def on_test_run_finished(_event)
38
+ publish_result
39
+ @io.flush
30
40
  end
31
41
 
32
- def scenario_name(keyword, name, file_colon_line, source_indent)
33
- if @scenario_tags.any? { |tag| tag.match(/@test#(\d+)/) }
34
- id = @scenario_tags.map { |tag| tag.match(/@test#(\d+)/) }.compact.first.captures.first.to_i
42
+ def scenario_name
43
+ path = "#{@current_feature[:uri]}:#{@scenario[:line]}"
44
+ scenario_tags= @scenario[:tags]
45
+ if scenario_tags.any? { |tag| tag.match(/@test#(\d+)/) }
46
+ id = scenario_tags.map { |tag| tag.match(/@test#(\d+)/) }.compact.first.captures.first.to_i
35
47
  @max_test_id = id if id > @max_test_id
36
48
 
37
- test_id_info = { name: name,
38
- path: file_colon_line }
49
+ test_id_info = { name: @scenario[:name],
50
+ path: path}
39
51
 
40
52
  if @test_id_mapping[id]
41
53
  if @duplicate_test_ids[id]
42
- @duplicate_test_ids[id] << test_id_info
54
+ @duplicate_test_ids[id].find do |dup|
55
+ @exist = true if dup[:path]== test_id_info[:path]
56
+ end
57
+ @duplicate_test_ids[id] << test_id_info unless @exist
43
58
  else
44
- @duplicate_test_ids[id] = [@test_id_mapping[id], test_id_info]
59
+ @duplicate_test_ids[id] = [@test_id_mapping[id], test_id_info] unless @test_id_mapping[id][:path] == test_id_info[:path]
45
60
  end
46
61
  else
47
62
  @test_id_mapping[id] = test_id_info
48
63
  end
49
-
50
64
  else
51
- @no_test_id[name] = file_colon_line unless @scenario_tags.include?('@dummy_test')
65
+ @no_test_id[@scenario[:name]] = path unless scenario_tags.include?('@dummy_test')
52
66
  end
53
- @scenario_tags = []
54
- end
55
-
56
- def after_features(features)
57
- publish_result
58
- @io.flush
67
+ @scenario[:tags] = []
59
68
  end
60
69
 
61
70
  private
71
+
62
72
  def publish_result
63
73
  content = {
64
74
  max: @max_test_id,
@@ -79,15 +89,14 @@ module QAT
79
89
  ------------------------------------
80
90
  #{dups_info.join("\n")}
81
91
  TXT
82
- puts duplicates_info
92
+ Kernel.puts duplicates_info
83
93
  end
84
94
 
85
- @io.puts(content.to_json({
86
- indent: ' ',
87
- space: ' ',
88
- object_nl: "\n"
89
- }))
95
+ @io.write (JSON.pretty_generate(content))
90
96
  end
97
+
98
+
99
+
91
100
  end
92
101
  end
93
102
  end
@@ -0,0 +1,65 @@
1
+
2
+ module QAT
3
+ module Formatter
4
+ # Helper for Formatters , most of the main methods are done to reduce code duplication
5
+ module UtilityFuction
6
+
7
+
8
+
9
+ def background(background)
10
+ @background_hash = {
11
+ keyword: background.keyword,
12
+ name: background.name,
13
+ description: background.description.nil? ? '' : background.description,
14
+ line: background.location.line,
15
+ type: 'background'
16
+ }
17
+ end
18
+
19
+ def create_feature_hash feature,uri
20
+ @feature_hash = {
21
+ id: feature.name,
22
+ uri: uri,
23
+ keyword: feature.keyword,
24
+ name: feature.name,
25
+ description: feature.description.nil? ? '' : feature.description,
26
+ line: feature.location.line
27
+ }
28
+ end
29
+
30
+ def get_lines_from_scenario(scenario_source, test_case)
31
+ if scenario_source.type == :Scenario
32
+ test_case.location.lines.max
33
+ else
34
+ test_case.location.lines.min
35
+ end
36
+ end
37
+
38
+ def calculate_row_number(scenario_source)
39
+ scenario_source.examples.table_body.each_with_index do |row, index|
40
+ return index + 1 if row == scenario_source.row
41
+ end
42
+ end
43
+
44
+ def get_example_values(scenario_source)
45
+ scenario_source.examples.table_body.each do |row|
46
+ if row == scenario_source.row
47
+ add_values_to_examples row[:cells]
48
+ end
49
+ end
50
+ end
51
+
52
+ def internal_hook?(test_step)
53
+ test_step.location.file.include?('lib/qat/cucumber/')
54
+ end
55
+
56
+ def support_hook?(test_step)
57
+ test_step.location.file.include?('features/support/hooks')
58
+ end
59
+
60
+
61
+
62
+
63
+ end
64
+ end
65
+ end
@@ -15,7 +15,7 @@ module TestIds
15
15
 
16
16
  update_test_ids(files, max_test_id)
17
17
  else
18
- puts "There are no scenarios without test id. Last test id given was '@test##{max_test_id}'."
18
+ Kernel.puts "There are no scenarios without test id. Last test id given was '@test##{max_test_id}'."
19
19
  end
20
20
  end
21
21
 
@@ -39,8 +39,8 @@ module TestIds
39
39
  #@param files [Array] list of files to change
40
40
  #@see TestIds::Helpers#map_untaged
41
41
  def announce_changes(files)
42
- puts "Giving test ids to scenarios:"
43
- puts files.to_json({
42
+ Kernel.puts "Giving test ids to scenarios:"
43
+ Kernel.puts files.to_json({
44
44
  indent: ' ',
45
45
  space: ' ',
46
46
  object_nl: "\n"
@@ -57,7 +57,7 @@ module TestIds
57
57
  files.each { |file, lines| max_test_id = rewrite_file(file, lines, max_test_id) }
58
58
  rescue
59
59
  path = File.join(Dir.pwd, 'public', 'test_ids_failed.feature')
60
- puts "Tag attribution failed! Check '#{path}' for more information!"
60
+ Kernel.puts "Tag attribution failed! Check '#{path}' for more information!"
61
61
  File.write(path, file_lines.join)
62
62
  end
63
63
  end
@@ -75,7 +75,7 @@ module TestIds
75
75
 
76
76
  norm_lines.size.times do
77
77
  line = norm_lines.shift
78
- puts "Editing file #{file} @ line #{line}."
78
+ Kernel.puts "Editing file #{file} @ line #{line}."
79
79
  max_test_id = add_tags(file_lines, line, max_test_id)
80
80
  end
81
81
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qat-cucumber
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.3
4
+ version: 7.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - QAT
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-01 00:00:00.000000000 Z
11
+ date: 2021-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cucumber
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2.4'
19
+ version: 5.2.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '2.4'
26
+ version: 5.2.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -72,28 +72,28 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '6.0'
75
+ version: '8.0'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '6.0'
82
+ version: '8.0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: qat-devel
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '6.0'
89
+ version: '8.0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '6.0'
96
+ version: '8.0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: httparty
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -138,14 +138,17 @@ files:
138
138
  - lib/qat/cucumber/time.rb
139
139
  - lib/qat/cucumber/version.rb
140
140
  - lib/qat/cucumber/world.rb
141
+ - lib/qat/formatter/builder.rb
141
142
  - lib/qat/formatter/console.rb
142
143
  - lib/qat/formatter/dashboard.rb
144
+ - lib/qat/formatter/helper.rb
143
145
  - lib/qat/formatter/loggable.rb
144
146
  - lib/qat/formatter/loggable/mdc.rb
145
147
  - lib/qat/formatter/loggable/scenario_info.rb
146
148
  - lib/qat/formatter/scenario/name.rb
147
149
  - lib/qat/formatter/tags.rb
148
150
  - lib/qat/formatter/test_ids.rb
151
+ - lib/qat/formatter/utility_function.rb
149
152
  - lib/qat/jenkins.rb
150
153
  - lib/qat/project/Gemfile
151
154
  - lib/qat/project/Rakefile
@@ -180,14 +183,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
180
183
  requirements:
181
184
  - - "~>"
182
185
  - !ruby/object:Gem::Version
183
- version: '2.3'
186
+ version: '2.5'
184
187
  required_rubygems_version: !ruby/object:Gem::Requirement
185
188
  requirements:
186
189
  - - ">="
187
190
  - !ruby/object:Gem::Version
188
191
  version: '0'
189
192
  requirements: []
190
- rubygems_version: 3.0.6
193
+ rubygems_version: 3.0.8
191
194
  signing_key:
192
195
  specification_version: 4
193
196
  summary: QAT is a Cucumber-based toolkit for automating tests.