Permalink
Browse files

Creating the index for real

  • Loading branch information...
1 parent 3ac10cb commit 21e467e247f65b7efbf28482d194c0238f68548d @qrush qrush committed Jul 10, 2009
Showing with 39 additions and 2 deletions.
  1. +3 −0 lib/report_card.rb
  2. +15 −0 lib/report_card/index.rb
  3. +17 −1 test/index_test.rb
  4. +4 −1 test/report_card_test.rb
View
@@ -3,6 +3,7 @@
require 'integrity'
require 'metric_fu'
require 'tinder'
+require 'erb'
require 'report_card/index'
require 'report_card/grader'
@@ -23,6 +24,8 @@ def self.grade
projects << project if grader.success?
end
end
+
+ Index.create(projects, config['site']) unless projects.empty?
end
def self.config
View
@@ -1,6 +1,21 @@
module ReportCard
class Index
+ TEMPLATE_PATH = File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "template", "index.html.erb"))
+
def self.create(projects, site)
+ new(projects.select { |p| p.public }, site)
+ new(projects.select { |p| ! p.public }, File.join(site, 'private'))
+ end
+
+ def initialize(projects, path)
+ @projects = projects
+
+ erb = File.read(TEMPLATE_PATH)
+ html = ERB.new(erb).result(binding)
+
+ File.open(File.join(path, "index.html"), "w") do |f|
+ f.write html
+ end
end
end
end
View
@@ -11,8 +11,24 @@ class IndexTest < Test::Unit::TestCase
@projects = [@public_project1, @public_project2, @private_project]
end
- should "create index" do
+ should "split up public and private projects" do
+ mock(ReportCard::Index).new([@public_project1, @public_project2], @site)
+ mock(ReportCard::Index).new([@private_project], File.join(@site, "private"))
+
ReportCard::Index.create(@projects, @site)
end
+
+ should "write out projects for each template" do
+ erb = "erb"
+ html = "html"
+ io = "io"
+ mock(io).write(html)
+
+ mock(File).read(ReportCard::Index::TEMPLATE_PATH) { erb }
+ mock(ERB).new(erb).mock!.result(anything) { html }
+ mock(File).open(File.join(@site, "index.html"), "w").yields(io)
+
+ ReportCard::Index.new([@private_project], @site)
+ end
end
end
View
@@ -3,7 +3,8 @@
class ReportCardTest < Test::Unit::TestCase
context "grading report_card" do
setup do
- @config = {'integrity_config' => '/path/to/integrity/config.yml'}
+ @config = {'integrity_config' => '/path/to/integrity/config.yml',
+ 'site' => '/path/to/site'}
stub(ReportCard).config { @config }
@project = Integrity::Project.new
@@ -19,6 +20,7 @@ class ReportCardTest < Test::Unit::TestCase
mock(grader).grade
mock(grader).success? { true }
mock(ReportCard::Grader).new(@project, @config) { grader }
+ mock(ReportCard::Index).create([@project], @config['site'])
ReportCard.grade
end
@@ -29,6 +31,7 @@ class ReportCardTest < Test::Unit::TestCase
mock(Integrity).new(@config['integrity_config'])
mock(Integrity::Project).all.mock!.each.yields(@project)
mock(ReportCard::Grader).new(@project, @config).never
+ mock(ReportCard::Index).create(anything, anything).never
ReportCard.grade
end
end

0 comments on commit 21e467e

Please sign in to comment.