Class: Mutx::View::Parser
- Inherits:
-
Object
- Object
- Mutx::View::Parser
- Defined in:
- lib/mutx/view/parser.rb
Class Method Summary collapse
-
.adapt_to_mutx(source, result) ⇒ Object
Parses cucumber report html doc Divides in each parts of document.
- .extract_summary(source) ⇒ Object
- .feature_html(content = nil) ⇒ Object
-
.finished_statement?(source) ⇒ Boolean
Checks if report says that execution is finised.
- .get_elapsed_time_for_zero(source) ⇒ Object
- .get_scenarios_summary(source) ⇒ Object
-
.get_status(source) ⇒ Object
Returns the status present on html cucumber report.
-
.has_scenarios_executed?(source) ⇒ Boolean
Checks if has scenario results summary.
-
.mutx_info(result) ⇒ String
This is the information added to html report.
-
.no_scenario_but_green?(source) ⇒ Boolean
Checks if result report is about no scenarios executed (scenarios not found).
- .resolve_style(line) ⇒ Object
Class Method Details
.adapt_to_mutx(source, result) ⇒ Object
Parses cucumber report html doc Divides in each parts of document
10 11 12 13 14 15 16 |
# File 'lib/mutx/view/parser.rb', line 10 def self.adapt_to_mutx(source, result) source.gsub! 'Collapse All</p></div></div></div>'," Collapse All</p></div></div></div> <div>#{mutx_info(result)}</div>" # end source.inspect end |
.extract_summary(source) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/mutx/view/parser.rb', line 31 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 |
.feature_html(content = nil) ⇒ Object
78 79 80 81 82 83 84 85 86 |
# File 'lib/mutx/view/parser.rb', line 78 def self.feature_html content=nil html = "<table> " content.each_line do |line| html += "#{self.resolve_style(line)} " end html += "</table>" end |
.finished_statement?(source) ⇒ Boolean
Checks if report says that execution is finised
51 52 53 |
# File 'lib/mutx/view/parser.rb', line 51 def self.finished_statement? source !(source =~ /Finished in .*s seconds/).nil? end |
.get_elapsed_time_for_zero(source) ⇒ Object
70 71 72 |
# File 'lib/mutx/view/parser.rb', line 70 def self.get_elapsed_time_for_zero(source) "0 Scenarios " + source.scan(/Finished in <strong>0m0.000s seconds/).first.gsub("<strong>","") end |
.get_scenarios_summary(source) ⇒ Object
74 75 76 |
# File 'lib/mutx/view/parser.rb', line 74 def self.get_scenarios_summary(source) source.scan(/\d+\sscenario.*\)/).first.gsub(/\<.+\>/,' - ') end |
.get_status(source) ⇒ Object
Returns the status present on html cucumber report
44 45 46 |
# File 'lib/mutx/view/parser.rb', line 44 def self.get_status(source) source.scan(/\d\sscenarios?\s\(\d+\s(\w+)/i).flatten.first if finished_statement?(source) end |
.has_scenarios_executed?(source) ⇒ Boolean
Checks if has scenario results summary
65 66 67 |
# File 'lib/mutx/view/parser.rb', line 65 def self.has_scenarios_executed? source (source.include? "scenario") and (source.scan(/\d+\sscenario.*\)/).size > 0) end |
.mutx_info(result) ⇒ String
This is the information added to html report
21 22 23 24 25 26 27 28 29 |
# File 'lib/mutx/view/parser.rb', line 21 def self.mutx_info(result) info = "<h2><strong>Task:</strong> #{result.task_name}</h2>" info += "<h4>Execution name: #{result.execution_name.gsub('-_-',' ')}</h4>" unless result.execution_name.empty? info += "<h4>Command: #{result.command}</h4>" #info += "<h4>Custom Params: #{result.custom_params_values.split('=').last}</h4>" info += "<h4>Started: #{result.started_at_formatted}</h4>" info += "<h4>Commit ID: #{result.git_log.split('\n').first}</h4>" info += "<h4><input type='button' onclick='window.close();' value='Close this window' />" end |
.no_scenario_but_green?(source) ⇒ Boolean
Checks if result report is about no scenarios executed (scenarios not found)
58 59 60 |
# File 'lib/mutx/view/parser.rb', line 58 def self.no_scenario_but_green?(source) source.include? '0m0.000s seconds' end |
.resolve_style(line) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/mutx/view/parser.rb', line 88 def self.resolve_style line line = line.gsub("<","<").gsub(">",">").gsub("'","").gsub('"',"").gsub("\n","<br>").gsub("<","<b><").gsub(">","></b>") styled = case line when /#.*/ "<tr style='color:grey;'><td>#{line}</td></tr>" when /^Característica|Feature.*/ "<tr style='color:black;'><td><b>#{line}</b></td></tr>" when /^Given|When|Then|And|But|\*|Dado|Cuando|Entonces|Y|Pero.*/ "<tr style='color:blue;'><td> #{line}</td></tr>" when /^Scenario|Escenario|Esquema|Antecedentes|Background.*/ "<tr style='color:red;'><td><b>#{line}</b></td></tr>" when /^Examples|Ejemplo.*/ "<tr style='color:red;'><td><b> #{line}</b></td></tr>" when /\|.*/ "<tr style='color:red;'><td> #{line}</td></tr>" when /^@.*/ "<tr><td><br></td></tr><tr style='color:green;'><td>#{line}</td></tr>" else "<tr><td> #{line}</td></tr>" end end |