onlyoffice_rspec_result_parser 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/onlyoffice_rspec_result_parser.rb +4 -0
- data/lib/onlyoffice_rspec_result_parser/helper/string_helper.rb +15 -0
- data/lib/onlyoffice_rspec_result_parser/rspec_result_parser.rb +65 -0
- data/lib/onlyoffice_rspec_result_parser/rspec_result_parser/describe.rb +18 -0
- data/lib/onlyoffice_rspec_result_parser/rspec_result_parser/example.rb +84 -0
- data/lib/onlyoffice_rspec_result_parser/rspec_result_parser/result_creator.rb +17 -0
- data/lib/onlyoffice_rspec_result_parser/rspec_result_parser/rspec_result.rb +114 -0
- data/lib/onlyoffice_rspec_result_parser/version.rb +6 -0
- metadata +86 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1e0498075e6fc9529b3ab53e7b99fef574e7e02a8a185e59d7889010402c97a5
|
4
|
+
data.tar.gz: ad609118fa567af873dcbc09875942b01d306bf91ea80ef4dfe2346e51d3f271
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3060d19a305e4fa19ee1b1c7c9371f141d93f345fcb2dfa9178b3b71f7d3a332a767d70691b6d7a457eed737342f07ccce632d851ceed5af31e6b0630bc44b7a
|
7
|
+
data.tar.gz: f455696715c4921e44dc463c68e28ca075860fd09a63418da47649a377f096846f4dd7ba65ec92a09910f73c79200a414736e100a8262d86eebcf33dab7148ef
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OnlyofficeRspecResultParser
|
4
|
+
# Class for string methods
|
5
|
+
class StringHelper
|
6
|
+
def self.get_style_param(string, param)
|
7
|
+
m = string.match(/#{param}:\s(.*);/)
|
8
|
+
m[1]
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.delete_px(string)
|
12
|
+
string.gsub 'px', ''
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'nokogiri'
|
4
|
+
require 'uri'
|
5
|
+
|
6
|
+
require_relative 'helper/string_helper'
|
7
|
+
require_relative 'rspec_result_parser/describe'
|
8
|
+
require_relative 'rspec_result_parser/example'
|
9
|
+
require_relative 'rspec_result_parser/result_creator'
|
10
|
+
require_relative 'rspec_result_parser/rspec_result'
|
11
|
+
|
12
|
+
module OnlyofficeRspecResultParser
|
13
|
+
# Class with stored data about rspec result
|
14
|
+
class ResultParser
|
15
|
+
@example_index = 0
|
16
|
+
|
17
|
+
class << self
|
18
|
+
attr_accessor :example_index
|
19
|
+
|
20
|
+
def parse_rspec_html(html_path)
|
21
|
+
page = Nokogiri::HTML(read_file(html_path))
|
22
|
+
parse_test_result(page)
|
23
|
+
end
|
24
|
+
|
25
|
+
# @param file [String] path to file
|
26
|
+
# @return [RspecResult] result of parsing
|
27
|
+
def parse_metadata(file)
|
28
|
+
page = Nokogiri::HTML(read_file(file))
|
29
|
+
parse_test_result(page, with_describe_info: false)
|
30
|
+
end
|
31
|
+
|
32
|
+
alias parse_rspec_html_string parse_rspec_html
|
33
|
+
|
34
|
+
def get_failed_cases_count_from_html(html_path)
|
35
|
+
page = Nokogiri::HTML(read_file(html_path))
|
36
|
+
RspecResult.new.parse_page(page, true).failed_count
|
37
|
+
end
|
38
|
+
|
39
|
+
def get_total_result_of_rspec_html(html_path)
|
40
|
+
page = Nokogiri::HTML(read_file(html_path))
|
41
|
+
RspecResult.new.parse_page(page, true).total
|
42
|
+
end
|
43
|
+
|
44
|
+
# @param page [String] data in page
|
45
|
+
# @param with_describe_info [Boolean] if
|
46
|
+
# describe metadata should be included
|
47
|
+
# @return [RspecResult] result of parsing
|
48
|
+
def parse_test_result(page, with_describe_info: true)
|
49
|
+
ResultParser.example_index = 0
|
50
|
+
RspecResult.new.parse_page(page, with_describe_info)
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
# Read file from disk or use string
|
56
|
+
# @param data [String] filepath or data string
|
57
|
+
# @return [String] result of read
|
58
|
+
def read_file(data)
|
59
|
+
return data unless File.exist?(data)
|
60
|
+
|
61
|
+
File.read(data)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OnlyofficeRspecResultParser
|
4
|
+
# rspec describe data
|
5
|
+
class Describe
|
6
|
+
attr_accessor :child, :text
|
7
|
+
|
8
|
+
def initialize(text, child = [], result = nil)
|
9
|
+
@text = text
|
10
|
+
@child = child
|
11
|
+
@result = result
|
12
|
+
end
|
13
|
+
|
14
|
+
def find_last_on_lvl(level)
|
15
|
+
level.zero? ? self : @child.last.find_last_on_lvl(level - 1)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OnlyofficeRspecResultParser
|
4
|
+
# rspec example data
|
5
|
+
class Example
|
6
|
+
attr_accessor :text, :duration, :message, :backtrace, :code, :log, :passed
|
7
|
+
# @return [String] link to page url
|
8
|
+
attr_accessor :page_url
|
9
|
+
# @return [String] link to screenshot
|
10
|
+
attr_accessor :screenshot
|
11
|
+
|
12
|
+
def initialize(data)
|
13
|
+
fetch_data(data)
|
14
|
+
@page_url = fetch_page_url
|
15
|
+
@screenshot = fetch_screenshot
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def fetch_data(data)
|
21
|
+
@text = data.css('span').first.text
|
22
|
+
@passed = data[:class].split(' ')[1]
|
23
|
+
if @passed == 'failed'
|
24
|
+
fetch_failed_data(data)
|
25
|
+
elsif @passed == 'passed'
|
26
|
+
@duration = data.css('span')[1].text
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def fetch_page_url
|
31
|
+
return nil unless @message
|
32
|
+
|
33
|
+
message_url_line = @message.match(/^.*Page address:.*/)
|
34
|
+
return nil unless message_url_line
|
35
|
+
|
36
|
+
message_url_line.to_s.match(/'.*'/).to_s.delete("'")
|
37
|
+
end
|
38
|
+
|
39
|
+
def fetch_screenshot
|
40
|
+
return nil unless @message
|
41
|
+
|
42
|
+
screenshot_line = @message.match(/^.*Error screenshot:.*/)
|
43
|
+
return nil unless screenshot_line
|
44
|
+
|
45
|
+
screenshot_line.to_s.match(/'.*?'/).to_s.delete("'")
|
46
|
+
end
|
47
|
+
|
48
|
+
# Method make all links in text clickable
|
49
|
+
# @param [String] text current text
|
50
|
+
# @return [String] text with clickable link
|
51
|
+
def format_link(text)
|
52
|
+
links = URI.extract(text)
|
53
|
+
links.each do |current_link|
|
54
|
+
if current_link.end_with?('png', 'jpg')
|
55
|
+
text.gsub!(current_link, link_url_50_percent(current_link))
|
56
|
+
elsif current_link.start_with?('http')
|
57
|
+
text.gsub!(current_link, link_url(current_link))
|
58
|
+
end
|
59
|
+
end
|
60
|
+
text
|
61
|
+
end
|
62
|
+
|
63
|
+
# Fetch data for failed case
|
64
|
+
# @param data [Nokogiri::XML::Element] element to parse
|
65
|
+
def fetch_failed_data(data)
|
66
|
+
@duration = data.css('span')[1].text
|
67
|
+
@message = format_link(data.css('div.message').text)
|
68
|
+
@backtrace = data.css('div.backtrace').text
|
69
|
+
@code = data.css('code').children.to_s
|
70
|
+
end
|
71
|
+
|
72
|
+
# @param [String] link to insert
|
73
|
+
# @return [String] result link with 50 percent size
|
74
|
+
def link_url_50_percent(link)
|
75
|
+
"<a href='#{link}'><img src='#{link}' height='50%' width='50%'></a>"
|
76
|
+
end
|
77
|
+
|
78
|
+
# @param [String] link to insert
|
79
|
+
# @return [String] result link
|
80
|
+
def link_url(link)
|
81
|
+
"<a href='#{link}'>#{link}</a>"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OnlyofficeRspecResultParser
|
4
|
+
# rspec ResultCreator methods
|
5
|
+
class ResultCreator
|
6
|
+
# @return [Describe] result describe
|
7
|
+
attr_reader :final_result
|
8
|
+
|
9
|
+
def push_to_end(describe, level)
|
10
|
+
if level.zero?
|
11
|
+
@final_result = describe
|
12
|
+
elsif level.positive?
|
13
|
+
@final_result.find_last_on_lvl(level - 1).child << describe
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OnlyofficeRspecResultParser
|
4
|
+
# class for storing rspec result
|
5
|
+
class RspecResult
|
6
|
+
LEVEL_MARGIN = 15
|
7
|
+
|
8
|
+
attr_accessor :processing, :result, :time, :total, :describe
|
9
|
+
# @return [Integer] how much tests failed
|
10
|
+
attr_accessor :failed_count
|
11
|
+
# @return [Integer] how much tests passed
|
12
|
+
attr_accessor :passed_count
|
13
|
+
# @return [Integer] how much tests pending
|
14
|
+
attr_accessor :pending_count
|
15
|
+
|
16
|
+
# @return [Integer] total test result count
|
17
|
+
def total_tests_count
|
18
|
+
failed_count + passed_count
|
19
|
+
end
|
20
|
+
|
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)
|
30
|
+
self
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def get_describe(page)
|
36
|
+
results = ResultCreator.new
|
37
|
+
page.at_css('div.results').xpath('./div').each do |current|
|
38
|
+
results.push_to_end(parse_describe(current),
|
39
|
+
get_describe_level(current))
|
40
|
+
end
|
41
|
+
results.final_result
|
42
|
+
end
|
43
|
+
|
44
|
+
def parse_describe(describe)
|
45
|
+
describe_obj = Describe.new(describe.css('dt').text)
|
46
|
+
unless describe.css('dd').empty?
|
47
|
+
describe.css('dd').each do |example|
|
48
|
+
describe_obj.child << Example.new(example)
|
49
|
+
ResultParser.example_index += 1
|
50
|
+
end
|
51
|
+
end
|
52
|
+
describe_obj
|
53
|
+
end
|
54
|
+
|
55
|
+
def get_describe_level(describe)
|
56
|
+
style_string = describe.xpath('./dl')[0][:style]
|
57
|
+
style_parameter = StringHelper.get_style_param(style_string,
|
58
|
+
'margin-left')
|
59
|
+
StringHelper.delete_px(style_parameter).to_i / LEVEL_MARGIN
|
60
|
+
end
|
61
|
+
|
62
|
+
def get_processing(page)
|
63
|
+
processing = page.css('script:contains("moveProgressBar")').last
|
64
|
+
return '0' unless processing
|
65
|
+
|
66
|
+
process = processing.text.strip.split('\'')[1]
|
67
|
+
if process == ''
|
68
|
+
'0'
|
69
|
+
else
|
70
|
+
process
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def get_total_result(page)
|
75
|
+
get_totals(page).include?(' 0 failures')
|
76
|
+
end
|
77
|
+
|
78
|
+
def get_totals(page)
|
79
|
+
totals = ''
|
80
|
+
total_elem = page.css('script:contains(" example")')
|
81
|
+
return totals unless total_elem
|
82
|
+
|
83
|
+
totals = total_elem.text.match(/"(.*?)"/)
|
84
|
+
if totals
|
85
|
+
totals[1]
|
86
|
+
else
|
87
|
+
''
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def get_failed_count(page)
|
92
|
+
page.xpath("//*[@class='example failed']").length
|
93
|
+
end
|
94
|
+
|
95
|
+
def get_passed_count(page)
|
96
|
+
page.xpath("//*[@class='example passed']").length
|
97
|
+
end
|
98
|
+
|
99
|
+
def get_pending_count(page)
|
100
|
+
page.xpath("//*[@class='example not_implemented']").length
|
101
|
+
end
|
102
|
+
|
103
|
+
def get_total_time(page)
|
104
|
+
total_time = page.css('script:contains("Finished in")')
|
105
|
+
.text
|
106
|
+
.match(/>(.*?)</)
|
107
|
+
if total_time
|
108
|
+
total_time[1]
|
109
|
+
else
|
110
|
+
''
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: onlyoffice_rspec_result_parser
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ONLYOFFICE
|
8
|
+
- Pavel Lobashov
|
9
|
+
- Ivan Tugin
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2020-03-20 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: nokogiri
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - "~>"
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.6'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - "~>"
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: '1.6'
|
29
|
+
- !ruby/object:Gem::Dependency
|
30
|
+
name: rake
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - "~>"
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '13.0'
|
36
|
+
type: :development
|
37
|
+
prerelease: false
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - "~>"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '13.0'
|
43
|
+
description: Gem to parse rspec results. Needed in wrata project
|
44
|
+
email:
|
45
|
+
- shockwavenn@gmail.com
|
46
|
+
executables: []
|
47
|
+
extensions: []
|
48
|
+
extra_rdoc_files: []
|
49
|
+
files:
|
50
|
+
- lib/onlyoffice_rspec_result_parser.rb
|
51
|
+
- lib/onlyoffice_rspec_result_parser/helper/string_helper.rb
|
52
|
+
- lib/onlyoffice_rspec_result_parser/rspec_result_parser.rb
|
53
|
+
- lib/onlyoffice_rspec_result_parser/rspec_result_parser/describe.rb
|
54
|
+
- lib/onlyoffice_rspec_result_parser/rspec_result_parser/example.rb
|
55
|
+
- lib/onlyoffice_rspec_result_parser/rspec_result_parser/result_creator.rb
|
56
|
+
- lib/onlyoffice_rspec_result_parser/rspec_result_parser/rspec_result.rb
|
57
|
+
- lib/onlyoffice_rspec_result_parser/version.rb
|
58
|
+
homepage: https://github.com/onlyoffice-testing-robot/onlyoffice_rspec_result_parser
|
59
|
+
licenses:
|
60
|
+
- AGPL-3.0
|
61
|
+
metadata:
|
62
|
+
bug_tracker_uri: https://github.com/onlyoffice-testing-robot/onlyoffice_rspec_result_parser/issues
|
63
|
+
changelog_uri: https://github.com/onlyoffice-testing-robot/onlyoffice_rspec_result_parser/blob/master/CHANGELOG.md
|
64
|
+
documentation_uri: https://www.rubydoc.info/gems/onlyoffice_rspec_result_parser
|
65
|
+
homepage_uri: https://github.com/onlyoffice-testing-robot/onlyoffice_rspec_result_parser
|
66
|
+
source_code_uri: https://github.com/onlyoffice-testing-robot/onlyoffice_rspec_result_parser
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.3'
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
requirements: []
|
82
|
+
rubygems_version: 3.0.6
|
83
|
+
signing_key:
|
84
|
+
specification_version: 4
|
85
|
+
summary: Gem to parse rspec results
|
86
|
+
test_files: []
|