Skip to content

Commit

Permalink
Generate an index.html file in the report dir. Release 0.4.3.
Browse files Browse the repository at this point in the history
  • Loading branch information
aslakhellesoy committed Jun 25, 2011
1 parent b5e3382 commit 27b2409
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 12 deletions.
10 changes: 5 additions & 5 deletions Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
aruba (0.4.2)
aruba (0.4.3)
bcat (>= 0.6.1)
childprocess (>= 0.1.9)
cucumber (>= 0.10.7)
Expand All @@ -16,17 +16,17 @@ GEM
builder (3.0.0)
childprocess (0.1.9)
ffi (~> 1.0.6)
cucumber (0.10.7)
cucumber (1.0.0)
builder (>= 2.1.2)
diff-lcs (>= 1.1.2)
gherkin (~> 2.4.0)
gherkin (~> 2.4.1)
json (>= 1.4.6)
term-ansicolor (>= 1.0.5)
diff-lcs (1.1.2)
ffi (1.0.9)
gherkin (2.4.0)
gherkin (2.4.1)
json (>= 1.4.6)
json (1.5.2)
json (1.5.3)
rack (1.3.0)
rdiscount (1.6.8)
rspec (2.6.0)
Expand Down
4 changes: 4 additions & 0 deletions History.md
@@ -1,3 +1,7 @@
## [v0.4.3](https://github.com/cucumber/aruba/compare/v0.4.2...v0.4.3)

* Aruba reporting now creates an index file for reports, linking them all together. (Aslak Hellesøy)

## [v0.4.2](https://github.com/cucumber/aruba/compare/v0.4.1...v0.4.2)

* Appending to a file creates the parent directory if it doesn't exist. (Aslak Hellesøy)
Expand Down
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -96,6 +96,7 @@ Aruba can generate a HTML page for each scenario that contains:
* The output from those commands (in colour if the output uses ANSI escapes)
* The files that were created (syntax highlighted in in colour)

In addition to this, it creates an `index.html` file with links to all individual report files.
Reporting is off by default, but you can enable it by defining the `ARUBA_REPORT_DIR` environment variable, giving it the value
where reports should be written:

Expand Down
2 changes: 1 addition & 1 deletion aruba.gemspec
Expand Up @@ -2,7 +2,7 @@

Gem::Specification.new do |s|
s.name = 'aruba'
s.version = '0.4.2'
s.version = '0.4.3'
s.authors = ["Aslak Hellesøy", "David Chelimsky", "Mike Sassak"]
s.description = 'CLI Steps for Cucumber, hand-crafted for you in Aruba'
s.summary = "aruba-#{s.version}"
Expand Down
35 changes: 30 additions & 5 deletions lib/aruba/reporting.rb
Expand Up @@ -10,6 +10,14 @@

module Aruba
module Reporting
class << self
def reports
@reports ||= Hash.new do |hash, feature|
hash[feature] = []
end
end
end

def pygmentize(file)
pygmentize = Process.new(%{pygmentize -f html -O encoding=utf-8 "#{file}"}, 3, 0.5)
pygmentize.run! do |p|
Expand Down Expand Up @@ -75,23 +83,40 @@ def template(path)
def depth
File.dirname(@scenario.feature.file).split('/').length
end

def index
erb = ERB.new(template('index.erb'), nil, '-')
erb.result(binding)
end

def index_title
"Examples"
end
end
end
World(Aruba::Reporting)

Before do |scenario|
After do |scenario|
@scenario = scenario
end

After do
report_file = File.join(ENV['ARUBA_REPORT_DIR'], "#{@scenario.feature.file}:#{@scenario.line}.html")
html_file = "#{scenario.feature.file}:#{scenario.line}.html"
report_file = File.join(ENV['ARUBA_REPORT_DIR'], html_file)
_mkdir(File.dirname(report_file))
File.open(report_file, 'w') do |io|
io.write(report)
end

Aruba::Reporting.reports[scenario.feature] << [scenario, html_file]

FileUtils.cp_r(File.join(ENV['ARUBA_REPORT_TEMPLATES'], '.'), ENV['ARUBA_REPORT_DIR'])
Dir["#{ENV['ARUBA_REPORT_DIR']}/**/*.erb"].each{|f| FileUtils.rm(f)}
end

at_exit do
index_file = File.join(ENV['ARUBA_REPORT_DIR'], "index.html")
extend(Aruba::Reporting)
File.open(index_file, 'w') do |io|
io.write(index)
end
end
end

20 changes: 20 additions & 0 deletions templates/index.erb
@@ -0,0 +1,20 @@
<!doctype html>

<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8"/>
<title><%= index_title %></title>
</head>
<body>

<h2><%= index_title %></h2>
<% Aruba::Reporting.reports.keys.sort{|f1, f2| f1.title <=> f2.title}.each do |feature| -%>
<h3><%= feature.title %></h3>
<ul>
<% Aruba::Reporting.reports[feature].each do |scenario, report_path| %>
<li><a href="<%= report_path%>"><%= scenario.title %></a></li>
<% end -%>
</ul>
<% end -%>

</body>
2 changes: 1 addition & 1 deletion templates/main.erb
Expand Up @@ -26,7 +26,7 @@
<h3>Output</h3>
<pre class="console">
<% commands.each do |cmd| -%>
<%= cmd %>
$ <%= cmd %>
<% end -%>
<%= output %>
</pre>
Expand Down

0 comments on commit 27b2409

Please sign in to comment.