Class: Kaya::View::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/kaya/view/parser.rb

Class Method Summary collapse

Class Method Details

.adapt_to_kaya(source, result) ⇒ Object

Parses cucumber report html doc Divides in each parts of document

Parameters:

  • source (String)

    the html code

  • the (Kaya::Result)

    result object



9
10
11
12
13
14
15
# File 'lib/kaya/view/parser.rb', line 9

def self.adapt_to_kaya(source, result)
    source.gsub! 'Collapse All</p></div></div></div>',"
      Collapse All</p></div></div></div>
        <div>#{kaya_info(result)}</div>"
  # end
  source.inspect
end

.extract_summary(source) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/kaya/view/parser.rb', line 30

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

.finished_statement?(source) ⇒ Boolean

Checks if report says that execution is finised

Parameters:

  • source (String)

    the entire report html code

Returns:

  • (Boolean)

    true if report says finished



50
51
52
# File 'lib/kaya/view/parser.rb', line 50

def self.finished_statement? source
  !(source =~ /Finished in .*s seconds/).nil?
end

.get_elapsed_time_for_zero(source) ⇒ Object



69
70
71
# File 'lib/kaya/view/parser.rb', line 69

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



73
74
75
# File 'lib/kaya/view/parser.rb', line 73

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

Parameters:

  • the (String)

    entire report html code



43
44
45
# File 'lib/kaya/view/parser.rb', line 43

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

Parameters:

  • the (String)

    entire report html source code

Returns:

  • (Boolean)

    true if there is scenarios executed



64
65
66
# File 'lib/kaya/view/parser.rb', line 64

def self.has_scenarios_executed? source
  (source.include? "scenario") and (source.scan(/\d+\sscenario.*\)/).size > 0)
end

.kaya_info(result) ⇒ String

This is the information added to html report

Parameters:

Returns:

  • (String)

    the html to be added



20
21
22
23
24
25
26
27
28
# File 'lib/kaya/view/parser.rb', line 20

def self.kaya_info(result)
  info  = "<h2><strong>Suite:</strong> #{result.suite_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)

Parameters:

  • the (String)

    entire report html source code

Returns:

  • (Boolean)

    true if is finished (green) and no scenarios executed (It means that is empty. No scenarios executed)



57
58
59
# File 'lib/kaya/view/parser.rb', line 57

def self.no_scenario_but_green?(source)
  source.include? '0m0.000s seconds'
end