onlyoffice_rspec_result_parser 0.1.1 → 0.1.2

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: 90e494964654c9785bcf0e3576c891c74995aa19bbea965bdf02788047b886db
4
- data.tar.gz: 417b08f08a82b69cf705be228a1b693a31cbfebab837a1e17bb97cd56c5df385
3
+ metadata.gz: de345de09e6bcbeb4b5a175a6e06d22986684da50e75ea860e700c9c3d161675
4
+ data.tar.gz: 7bba8b2ba22b9a9c94a8faa2f475353037b8f8bf0602c9bcccad19c416614ccd
5
5
  SHA512:
6
- metadata.gz: a70703d0688597535b338adcf5782db1653731ff6708188abdb84310cf9042821978f19e80afc0dbbc79d11c7a1f45ae674884403faf01cd2fd2b86b1ecc50a0
7
- data.tar.gz: c0db9d126625febd4a249f7f6a9c3c12dc8b23f15ba13af3eae33ff13624eaa928db866d20ba0c10cbcbcec7d75255bea53fd8cb2bb518dec9c20b4814652ccd
6
+ metadata.gz: 2175fc3e4324f977c83b39ad2142f765bfe1b4bd9248587f719e75de9cf638087a0f230fcb9841493abdbd98495b6c49dbb3c033a45ea6cccfb577b1514c5aa1
7
+ data.tar.gz: 3c862db57ea7ed237a9a8c662be49a15d81563e78921a5dd402ff484ca94ecfb37e8da211c38b8dd2768a6771262a160b87d46a81dd4608e9c9e45bf76c9dcd4
@@ -32,17 +32,19 @@ module OnlyofficeRspecResultParser
32
32
  alias parse_rspec_html_string parse_rspec_html
33
33
 
34
34
  def get_failed_cases_count_from_html(html_path)
35
- return 0 if html_path.empty?
36
-
37
35
  page = Nokogiri::HTML(read_file(html_path))
38
- RspecResult.new.parse_page(page, true).failed_count
36
+ result = RspecResult.new(page).parse_page(true)
37
+ return 0 unless result.valid_html?
38
+
39
+ result.failed_count
39
40
  end
40
41
 
41
42
  def get_total_result_of_rspec_html(html_path)
42
- return html_path if html_path.empty?
43
-
44
43
  page = Nokogiri::HTML(read_file(html_path))
45
- RspecResult.new.parse_page(page, true).total
44
+ result = RspecResult.new(page).parse_page(true)
45
+ return '' unless result.valid_html?
46
+
47
+ result.total
46
48
  end
47
49
 
48
50
  # @param page [String] data in page
@@ -51,7 +53,7 @@ module OnlyofficeRspecResultParser
51
53
  # @return [RspecResult] result of parsing
52
54
  def parse_test_result(page, with_describe_info: true)
53
55
  ResultParser.example_index = 0
54
- RspecResult.new.parse_page(page, with_describe_info)
56
+ RspecResult.new(page).parse_page(with_describe_info)
55
57
  end
56
58
 
57
59
  private
@@ -12,31 +12,46 @@ module OnlyofficeRspecResultParser
12
12
  attr_accessor :passed_count
13
13
  # @return [Integer] how much tests pending
14
14
  attr_accessor :pending_count
15
+ # @return [String] html page of RspecResult
16
+ attr_reader :page
17
+
18
+ def initialize(page)
19
+ @page = page
20
+ end
15
21
 
16
22
  # @return [Integer] total test result count
17
23
  def total_tests_count
18
24
  failed_count + passed_count
19
25
  end
20
26
 
21
- def parse_page(page, with_describe_info = true)
22
- @describe = get_describe(page) if with_describe_info
23
- @processing = get_processing(page)
24
- @result = get_total_result(page)
25
- @time = get_total_time(page)
26
- @total = get_totals(page)
27
- @failed_count = get_failed_count(page)
28
- @passed_count = get_passed_count(page)
29
- @pending_count = get_pending_count(page)
27
+ def parse_page(with_describe_info = true)
28
+ return self unless valid_html?
29
+
30
+ @describe = fetch_describe if with_describe_info
31
+ @processing = fetch_processing
32
+ @result = fetch_total_result
33
+ @time = fetch_total_time
34
+ @total = fetch_totals
35
+ @failed_count = fetch_failed_count
36
+ @passed_count = fetch_passed_count
37
+ @pending_count = fetch_pending_count
30
38
  self
31
39
  end
32
40
 
41
+ # @return [True, False] is html code is valid
42
+ def valid_html?
43
+ return false unless page.at_css('div.results')
44
+
45
+ true
46
+ end
47
+
33
48
  private
34
49
 
35
- def get_describe(page)
50
+ def fetch_describe
36
51
  results = ResultCreator.new
37
52
  page.at_css('div.results').xpath('./div').each do |current|
38
53
  results.push_to_end(parse_describe(current),
39
- get_describe_level(current))
54
+ fetch_describe_level(current))
40
55
  end
41
56
  results.final_result
42
57
  end
@@ -52,14 +67,14 @@ module OnlyofficeRspecResultParser
52
67
  describe_obj
53
68
  end
54
69
 
55
- def get_describe_level(describe)
70
+ def fetch_describe_level(describe)
56
71
  style_string = describe.xpath('./dl')[0][:style]
57
72
  style_parameter = StringHelper.get_style_param(style_string,
58
73
  'margin-left')
59
74
  StringHelper.delete_px(style_parameter).to_i / LEVEL_MARGIN
60
75
  end
61
76
 
62
- def get_processing(page)
77
+ def fetch_processing
63
78
  processing = page.css('script:contains("moveProgressBar")').last
64
79
  return '0' unless processing
65
80
 
@@ -71,11 +86,11 @@ module OnlyofficeRspecResultParser
71
86
  end
72
87
  end
73
88
 
74
- def get_total_result(page)
75
- get_totals(page).include?(' 0 failures')
89
+ def fetch_total_result
90
+ fetch_totals.include?(' 0 failures')
76
91
  end
77
92
 
78
- def get_totals(page)
93
+ def fetch_totals
79
94
  totals = ''
80
95
  total_elem = page.css('script:contains(" example")')
81
96
  return totals unless total_elem
@@ -88,19 +103,19 @@ module OnlyofficeRspecResultParser
88
103
  end
89
104
  end
90
105
 
91
- def get_failed_count(page)
106
+ def fetch_failed_count
92
107
  page.xpath("//*[@class='example failed']").length
93
108
  end
94
109
 
95
- def get_passed_count(page)
110
+ def fetch_passed_count
96
111
  page.xpath("//*[@class='example passed']").length
97
112
  end
98
113
 
99
- def get_pending_count(page)
114
+ def fetch_pending_count
100
115
  page.xpath("//*[@class='example not_implemented']").length
101
116
  end
102
117
 
103
- def get_total_time(page)
118
+ def fetch_total_time
104
119
  total_time = page.css('script:contains("Finished in")')
105
120
  .text
106
121
  .match(/>(.*?)</)
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OnlyofficeRspecResultParser
4
- VERSION = '0.1.1'
4
+ VERSION = '0.1.2'
5
5
  NAME = 'onlyoffice_rspec_result_parser'
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: onlyoffice_rspec_result_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - ONLYOFFICE
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2020-03-24 00:00:00.000000000 Z
13
+ date: 2020-04-03 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: nokogiri