Class: Hydra::Listener::CombineHtml

Inherits:
Object
  • Object
show all
Defined in:
lib/hydra/listener/cucumber_html_report.rb

Instance Method Summary collapse

Constructor Details

#initialize(output_file = nil) ⇒ CombineHtml

Returns a new instance of CombineHtml.



13
14
15
16
17
18
# File 'lib/hydra/listener/cucumber_html_report.rb', line 13

def initialize(output_file = nil)
  @results_path = File.join(Dir.pwd, 'results')
  output_file = File.join(@results_path, 'html/index.html') if output_file.nil?
  @io = File.open(output_file, "w")
  @builder = create_builder(@io)
end

Instance Method Details

#after_featuresObject



81
82
83
84
85
# File 'lib/hydra/listener/cucumber_html_report.rb', line 81

def after_features
  @builder << '</div>'
  @builder << '</body>'
  @builder << '</html>'
end

#before_featuresObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/hydra/listener/cucumber_html_report.rb', line 46

def before_features
  # <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  @builder.declare!(
    :DOCTYPE,
    :html,
    :PUBLIC,
    '-//W3C//DTD XHTML 1.0 Strict//EN',
    'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'
  )

  @builder << '<html xmlns ="http://www.w3.org/1999/xhtml">'
    @builder.head do
    @builder.meta(:content => 'text/html;charset=utf-8')
    @builder.title 'Cucumber'
    inline_css
    inline_js
  end
  @builder << '<body>'
  #@builder << "<!-- Step count #{@step_count}-->"
  @builder << '<div class="cucumber">'
  @builder.div(:id => 'cucumber-header') do
    @builder.div(:id => 'label') do
      @builder.h1('Cucumber Features')
    end
    @builder.div(:id => 'summary') do
      @builder.p('',:id => 'totals')
      @builder.p('',:id => 'duration')
      @builder.div(:id => 'expand-collapse') do
        @builder.p('Expand All', :id => 'expander')
        @builder.p('Collapse All', :id => 'collapser')
      end
    end
  end
end

#combine_featuresObject



35
36
37
38
39
40
41
42
43
44
# File 'lib/hydra/listener/cucumber_html_report.rb', line 35

def combine_features
  wait_for_two_seconds_while_files_are_written
  Dir.glob(File.join(@results_path, 'features/*.html')).sort.each do |feature|
    File.open( feature, "rb") do |f|
      f.each_line do |line|
        @builder << line
      end
    end
  end
end

#create_builder(io) ⇒ Object



143
144
145
# File 'lib/hydra/listener/cucumber_html_report.rb', line 143

def create_builder(io)
  Cucumber::Formatter::OrderedXmlMarkup.new(:target => io, :indent => 0)
end

#generateObject



20
21
22
23
24
25
26
27
28
29
# File 'lib/hydra/listener/cucumber_html_report.rb', line 20

def generate
  before_features
  combine_features
  after_features
  @io.flush
  @io.close


  FileUtils.rm_r File.join(@results_path, 'features')
end

#inline_cssObject



88
89
90
91
92
# File 'lib/hydra/listener/cucumber_html_report.rb', line 88

def inline_css
  @builder.style(:type => 'text/css') do
    @builder << File.read(File.dirname(__FILE__) + '/cucumber.css')
  end
end

#inline_jqueryObject



101
102
103
# File 'lib/hydra/listener/cucumber_html_report.rb', line 101

def inline_jquery
  File.read(File.dirname(__FILE__) + '/jquery-min.js')
end

#inline_jsObject



94
95
96
97
98
99
# File 'lib/hydra/listener/cucumber_html_report.rb', line 94

def inline_js
  @builder.script(:type => 'text/javascript') do
    @builder << inline_jquery
    @builder << inline_js_content
  end
end

#inline_js_contentObject



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/hydra/listener/cucumber_html_report.rb', line 105

def inline_js_content
  <<-EOF

  SCENARIOS = "h3[id^='scenario_']";

  $(document).ready(function() {
    $(SCENARIOS).css('cursor', 'pointer');
    $(SCENARIOS).click(function() {
$(this).siblings().toggle(250);
    });

    $("#collapser").css('cursor', 'pointer');
    $("#collapser").click(function() {
$(SCENARIOS).siblings().hide();
    });

    $("#expander").css('cursor', 'pointer');
    $("#expander").click(function() {
$(SCENARIOS).siblings().show();
    });
  })

  function moveProgressBar(percentDone) {
    $("cucumber-header").css('width', percentDone +"%");
  }
  function makeRed(element_id) {
    $('#'+element_id).css('background', '#C40D0D');
    $('#'+element_id).css('color', '#FFFFFF');
  }
  function makeYellow(element_id) {
    $('#'+element_id).css('background', '#FAF834');
    $('#'+element_id).css('color', '#000000');
  }

  EOF
end

#wait_for_two_seconds_while_files_are_writtenObject



31
32
33
# File 'lib/hydra/listener/cucumber_html_report.rb', line 31

def wait_for_two_seconds_while_files_are_written
  sleep 2
end