# encoding: utf-8 module Mutx module View class Parser # Parses cucumber report html doc # Divides in each parts of document # @param [String] source = the html code # @param [Mutx::Result] the result object def self.adapt_to_mutx(source, result) source.gsub! 'Collapse All

'," Collapse All

#{mutx_info(result)}
" # end source.inspect end # This is the information added to html report # @param [Mutx::Results::Result] result object # @return [String] the html to be added def self.mutx_info(result) info = "

Task: #{result.task_name}

" info += "

Execution name: #{result.execution_name.gsub('-_-',' ')}

" unless result.execution_name.empty? info += "

Command: #{result.command}

" info += "

Custom Params: #{result.custom_params_values.split('=').last}

" info += "

Started: #{result.started_at_formatted}

" info += "

Commit ID: #{result.git_log.split('\n').first}

" info += "

" end def self.extract_summary source if no_scenario_but_green?(source) # 0 scenarios executed get_elapsed_time_for_zero(source) elsif has_scenarios_executed?(source) # scenarios executed > 0 get_scenarios_summary(source) else "running" end end # Returns the status present on html cucumber report # @param [String] the entire report html code # @reurn [String] the text of status def self.get_status(source) source.scan(/\d\sscenarios?\s\(\d+\s(\w+)/i).flatten.first if finished_statement?(source) end # Checks if report says that execution is finised # @param [String] source = the entire report html code # @return [Boolean] true if report says finished def self.finished_statement? source !(source =~ /Finished in .*s seconds/).nil? end # Checks if result report is about no scenarios executed (scenarios not found) # @param [String] the entire report html source code # @return [Boolean] true if is finished (green) and no scenarios executed (It means that is empty. No scenarios executed) def self.no_scenario_but_green?(source) source.include? '0m0.000s seconds' end # Checks if has scenario results summary # @param [String] the entire report html source code # @return [Boolean] true if there is scenarios executed def self.has_scenarios_executed? source (source.include? "scenario") and (source.scan(/\d+\sscenario.*\)/).size > 0) end # def self.get_elapsed_time_for_zero(source) "0 Scenarios " + source.scan(/Finished in 0m0.000s seconds/).first.gsub("","") end def self.get_scenarios_summary(source) source.scan(/\d+\sscenario.*\)/).first.gsub(/\<.+\>/,' - ') end end end end