Revisions

gist: 141475 Download_button fork
public
Public Clone URL: git://gist.github.com/141475.git
Embed All Files: show embed
cucumber.css #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
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
body { min-width: 950px; }
.cucumber {
  background: #f4f4f4;
  color: #666;
  padding: 0 2% 1em;
  width: 58%;
}
 
.cucumber .feature h2 {
  font-size: 2.5em;
  border-bottom: 3px solid #ccc;
  padding: .5em 0;
}
 
.cucumber .feature p {
  font-size: 2em;
  line-height: 1.5em;
  font-weight: bold;
  color: #aaa;
  font-style: italic;
}
 
.cucumber .feature p, .cucumber .scenario, .cucumber .background {
  margin-left: 20px;
}
 
.cucumber .scenario, .cucumber .background {
  background: #eee;
  padding-bottom: 1px;
  margin-bottom: 2em;
  border: 1px solid #ccc;
}
 
.cucumber .scenario h3, .cucumber .background h3 {
  color: #666;
  padding: 10px;
  font-size: 1.75em;
  border-bottom: 1px solid #ccc;
  background: #e8e8e8;
  margin-bottom: 0;
}
 
.cucumber .scenario ol, .cucumber .background ol {
  margin-top: 1em;
  margin-left: 10px;
}
 
.cucumber .scenario li, .cucumber .background li {
  list-style-type: none;
  font-size: 1.375em;
  line-height: 1em;
  padding-left: 0;
  margin-left: .5em;
}
 
.cucumber .feature li { color: #777; }
.cucumber .feature li span { font-weight: bold; }
.cucumber .feature li div { display: inline-block; }
.cucumber .feature li.passed span.swatch { background: green; }
.cucumber .feature li.undefined span.swatch { background: yellow; }
.cucumber .feature li.pending span.swatch { background: yellow; }
.cucumber .feature li.failed span.swatch { background: red; }
.cucumber .feature li.skipped span.swatch { background: cyan; }
 
.cucumber .feature li span.swatch {
  display: inline-block;
  position: relative;
  top: .125em;
  width: 1em;
  height: 1em;
  margin-right: .25em;
}
 
.cucumber pre {
  border: 1px solid #aaa;
  line-height: 1.375em;
  font-size: 0.9em;
  background: #222;
  padding: 1em;
  margin: .5em 3em .5em 1.75em;
}
 
.cucumber table {
  border: 1px solid #ccc;
  width: auto;
  margin: 1em 0 0 1em;
}
 
.cucumber table tr:first-child td {
  font-weight: bold;
  border-bottom: 1px solid #ccc;
}
 
.toc {
  position: fixed;
  right: 0;
  top: 0;
  height: 100%;
  overflow: auto;
  width: 34%;
  min-width: 300px;
  background: #e9e9e9;
  border-left: 5px solid #ccc;
  padding: 0 2%;
}
.toc h2 {
  padding: .25em 0;
  font-size: 2.5em;
  color: #666;
  margin-bottom: 0;
}
 
.toc ul { margin: 0; }
.toc li.feature { margin: 0 0 1em 0;}
.toc li.feature:last-child { padding: 0 0 1em 0;}
.toc li.feature > a {
  font-size: 1.5em;
  font-weight: bold;
  padding: .25em .5em;
  display: inline-block;
}
 
.toc li.scenario {
  padding: .25em 1.5em;
}
.toc li.scenario > a {
  padding: .25em .5em;
  line-height: 1.25em;
}
cucumber.js #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
(function($) {
  $.fn.outerHTML = function() { return $("<div/>").append(this.eq(0).clone()).html(); };
  $.extend(String.prototype, {
    parameterize: function() {
      return this.replace(/[^\w]+/g, '-').replace(/^\-|\-$/g, '').toLowerCase();
    }
  });
 
  $(function(){
    // strip out escaped <span>'s
    $(".cucumber .scenario li, .cucumber .background li").each(function(idx, li) {
      var liHTML = $(li).html().replace(/&lt;(\/?span)&gt;/g, "<$1>");
      $(li).html(liHTML);
    });
 
    $(".cucumber .scenario li, .cucumber .background li").each(function(idx, li) {
      if(!$(li).find("span.swatch").length) {
        $(li).prepend($("<span class='swatch'>"));
      }
    });
 
    (function() {
      var $ulNavigation = $("<ul>").addClass("reset");
      $(".cucumber .feature").each(function(idx, feature) {
        var $ulScenarios = $("<ul>"),
            $feature = $(feature);
 
        $feature.find(".scenario").each(function(idx2, scenario) {
          var $scenario = $(scenario),
              scenarioText = $scenario.find("> :header").text();
          $scenario.find("> :header").attr("id", scenarioText.parameterize());
          $("<li class='scenario'>")
            .append($("<a>")
            .attr("href", "#" + scenarioText.parameterize())
            .text(scenarioText))
            .appendTo($ulScenarios);
        });
 
        var featureText = $feature.find("> :header").text();
        $feature.find("> :header").attr("id", featureText.parameterize());
 
        $("<li class='feature'>")
          .append(
            $("<a>")
              .attr("href", "#" + featureText.parameterize())
              .text(featureText)
          )
          .append($ulScenarios)
          .appendTo($ulNavigation);
      });
      $("<div class='toc'>")
        .append($("<h2>Feature Navigation</h2>"))
        .append($ulNavigation)
        .appendTo("body");
    })();
  });
})(jQuery);
file_ext.rb #
1
2
3
4
5
6
7
8
9
10
11
class File
  def self.string_to_file(string, path)
    directory = File.dirname(path)
    FileUtils.mkdir_p directory unless File.directory?(directory)
    File.open(path, 'w') { |f| f << string }
  end
 
  def self.path_to_string(path)
    File.new(path).read
  end
end
Ruby #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
namespace :cucumber do
  desc "Generates Cucumber results as an HTML file"
  task :generate_html => :environment do
    cucumber_output_path = File.join(RAILS_ROOT, "public", "cucumber.html")
    system("cucumber -p html_output > #{cucumber_output_path}")
    puts "Output Cucumber to public/cucumber.html"
    doc = Hpricot.parse(File.path_to_string(cucumber_output_path))
    puts "Parsing cucumber.html"
    doc.search("html head style:last") do |style|
      style.after %{
<link href="/stylesheets/reset.css" media="screen" rel="stylesheet" type="text/css" />
<link href="/stylesheets/forms.css" media="screen" rel="stylesheet" type="text/css" />
<link href="/stylesheets/extras.css" media="screen" rel="stylesheet" type="text/css" />
<link href="/stylesheets/screen.css" media="screen" rel="stylesheet" type="text/css" />
<link href="/stylesheets/admin.css" media="screen" rel="stylesheet" type="text/css" />
<link href="/stylesheets/cucumber.css" media="screen" rel="stylesheet" type="text/css" />
<script src="/javascripts/jquery-1.3.2.min.js" type="text/javascript"></script>
<script src="/javascripts/cucumber.js" type="text/javascript"></script>
}
    end
    puts "Saving cucumber.html"
    File.string_to_file(doc.to_html, cucumber_output_path)
  end
end