class OnlyofficeRspecResultParser::RspecResult
class for storing rspec result
Constants
- LEVEL_MARGIN
@return [Integer] margin value
Attributes
describe[RW]
failed_count[RW]
@return [Integer] how much tests failed
page[R]
@return [String] html page of RspecResult
passed_count[RW]
@return [Integer] how much tests passed
pending_count[RW]
@return [Integer] how much tests pending
processing[RW]
result[RW]
time[RW]
total[RW]
Public Class Methods
new(page)
click to toggle source
# File lib/onlyoffice_rspec_result_parser/rspec_result_parser/rspec_result.rb, line 19 def initialize(page) @page = page end
Public Instance Methods
parse_page(with_describe_info: true)
click to toggle source
Parse current page @param [Boolean] with_describe_info should info be parsed @return [RspecResult] result of parse
# File lib/onlyoffice_rspec_result_parser/rspec_result_parser/rspec_result.rb, line 31 def parse_page(with_describe_info: true) return self unless valid_html? @describe = fetch_describe if with_describe_info @processing = fetch_processing @result = fetch_total_result @time = fetch_total_time @total = fetch_totals @failed_count = fetch_failed_count @passed_count = fetch_passed_count @pending_count = fetch_pending_count self end
total_tests_count()
click to toggle source
@return [Integer] total test result count
# File lib/onlyoffice_rspec_result_parser/rspec_result_parser/rspec_result.rb, line 24 def total_tests_count failed_count + passed_count end
valid_html?()
click to toggle source
@return [True, False] is html code is valid
# File lib/onlyoffice_rspec_result_parser/rspec_result_parser/rspec_result.rb, line 46 def valid_html? return false unless page.at_css('div.results') true end
Private Instance Methods
fetch_describe()
click to toggle source
# File lib/onlyoffice_rspec_result_parser/rspec_result_parser/rspec_result.rb, line 54 def fetch_describe results = ResultCreator.new page.at_css('div.results').xpath('./div').each do |current| results.push_to_end(parse_describe(current), fetch_describe_level(current)) end results.final_result end
fetch_describe_level(describe)
click to toggle source
# File lib/onlyoffice_rspec_result_parser/rspec_result_parser/rspec_result.rb, line 74 def fetch_describe_level(describe) style_string = describe.xpath('./dl')[0][:style] style_parameter = StringHelper.get_style_param(style_string, 'margin-left') StringHelper.delete_px(style_parameter).to_i / LEVEL_MARGIN end
fetch_failed_count()
click to toggle source
# File lib/onlyoffice_rspec_result_parser/rspec_result_parser/rspec_result.rb, line 110 def fetch_failed_count page.xpath("//*[@class='example failed']").length end
fetch_passed_count()
click to toggle source
# File lib/onlyoffice_rspec_result_parser/rspec_result_parser/rspec_result.rb, line 114 def fetch_passed_count page.xpath("//*[@class='example passed']").length end
fetch_pending_count()
click to toggle source
# File lib/onlyoffice_rspec_result_parser/rspec_result_parser/rspec_result.rb, line 118 def fetch_pending_count page.xpath("//*[@class='example not_implemented']").length end
fetch_processing()
click to toggle source
# File lib/onlyoffice_rspec_result_parser/rspec_result_parser/rspec_result.rb, line 81 def fetch_processing processing = page.css('script:contains("moveProgressBar")').last return '0' unless processing process = processing.text.strip.split('\'')[1] if process == '' '0' else process end end
fetch_total_result()
click to toggle source
# File lib/onlyoffice_rspec_result_parser/rspec_result_parser/rspec_result.rb, line 93 def fetch_total_result fetch_totals.include?(' 0 failures') end
fetch_total_time()
click to toggle source
# File lib/onlyoffice_rspec_result_parser/rspec_result_parser/rspec_result.rb, line 122 def fetch_total_time total_time = page.css('script:contains("Finished in")') .text .match(/>(.*?)</) if total_time total_time[1] else '' end end
fetch_totals()
click to toggle source
# File lib/onlyoffice_rspec_result_parser/rspec_result_parser/rspec_result.rb, line 97 def fetch_totals totals = '' total_elem = page.css('script:contains(" example")') return totals unless total_elem totals = total_elem.text.match(/"(.*?)"/) if totals totals[1] else '' end end
parse_describe(describe)
click to toggle source
# File lib/onlyoffice_rspec_result_parser/rspec_result_parser/rspec_result.rb, line 63 def parse_describe(describe) describe_obj = Describe.new(describe.css('dt').text) unless describe.css('dd').empty? describe.css('dd').each do |example| describe_obj.child << Example.new(example) ResultParser.example_index += 1 end end describe_obj end