This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Renaming runner to grader

  • Loading branch information...
qrush committed Jul 8, 2009
1 parent 67f0029 commit 3cbb76645c458d3bc0ebbd893ec8f4b34f161c88
View
@@ -3,18 +3,18 @@
require 'tinder'
$:.unshift(File.dirname(__FILE__))
-require 'report_card/runner'
+require 'report_card/grader'
module ReportCard
CONFIG_FILE = "config.yml"
- def self.run
+ def self.grade
Integrity.new(config['integrity_config'])
ignore = config['ignore'] ? Regexp.new(config['ignore']) : /[^\w\d\s]+/
Integrity::Project.all.each do |project|
- ReportCard::Runner.new(project, config).run if project.name !~ ignore
+ ReportCard::Grader.new(project, config).grade if project.name !~ ignore
end
end
@@ -1,13 +1,13 @@
module ReportCard
- class Runner
+ class Grader
attr_reader :project, :config, :scores, :old_scores
def initialize(project, config)
@project = project
@config = config
end
- def run
+ def grade
return unless ready?
STDERR.puts ">> Building metrics for #{project.name}"
configure
@@ -1,66 +1,66 @@
require 'test_helper'
-class RunnerTest < Test::Unit::TestCase
- context "with a runner" do
+class GraderTest < Test::Unit::TestCase
+ context "with a grader" do
setup do
@project = Integrity::Project.new(:name => "awesome")
@config = {'url' => 'http://metrics.thoughtbot.com',
'site' => '/path/to/site'}
- @runner = ReportCard::Runner.new(@project, @config)
+ @grader = ReportCard::Grader.new(@project, @config)
stub(STDERR).puts(anything)
end
- should "not even run if not ready" do
- mock(@runner).ready? { false }
- mock(@runner).configure.never
- mock(@runner).generate.never
- mock(@runner).wrapup.never
- @runner.run
+ should "not even grade if not ready" do
+ mock(@grader).ready? { false }
+ mock(@grader).configure.never
+ mock(@grader).generate.never
+ mock(@grader).wrapup.never
+ @grader.grade
end
- should "run and wrapup if successful" do
- mock(@runner).ready? { true }
- mock(@runner).configure
- mock(@runner).generate
- mock(@runner).success? { true }
- mock(@runner).wrapup
- @runner.run
+ should "grade and wrapup if successful" do
+ mock(@grader).ready? { true }
+ mock(@grader).configure
+ mock(@grader).generate
+ mock(@grader).success? { true }
+ mock(@grader).wrapup
+ @grader.grade
end
- should "run and not wrapup if unsuccessful" do
- mock(@runner).ready? { true }
- mock(@runner).configure
- mock(@runner).generate
- mock(@runner).success? { false }
- mock(@runner).wrapup.never
- @runner.run
+ should "grade and not wrapup if unsuccessful" do
+ mock(@grader).ready? { true }
+ mock(@grader).configure
+ mock(@grader).generate
+ mock(@grader).success? { false }
+ mock(@grader).wrapup.never
+ @grader.grade
end
should "score and notify when wrapping up" do
- mock(@runner).score
- mock(@runner).score_changed? { true }
- mock(@runner).notify
- @runner.wrapup
+ mock(@grader).score
+ mock(@grader).score_changed? { true }
+ mock(@grader).notify
+ @grader.wrapup
end
should "score and not notify when wrapping up and the score hasn't changed" do
- mock(@runner).score
- mock(@runner).score_changed? { false }
- mock(@runner).notify.never
- @runner.wrapup
+ mock(@grader).score
+ mock(@grader).score_changed? { false }
+ mock(@grader).notify.never
+ @grader.wrapup
end
should "store project and config" do
- assert_equal @runner.project, @project
- assert_equal @runner.config, @config
+ assert_equal @grader.project, @project
+ assert_equal @grader.config, @config
end
should "change directory to the export directory if it exists" do
directory = "dir"
mock(Integrity::ProjectBuilder).new(@project).mock!.send(:export_directory) { directory }
mock(File).exist?(directory) { true }
mock(Dir).chdir(directory) { 0 }
- assert @runner.ready?
+ assert @grader.ready?
end
should "not change directory to the export directory if it does not exists" do
@@ -69,7 +69,7 @@ class RunnerTest < Test::Unit::TestCase
mock(File).exist?(directory) { false }
mock(Dir).chdir(anything).never
mock(STDERR).puts(anything)
- assert ! @runner.ready?
+ assert ! @grader.ready?
end
context "with a public project" do
@@ -78,13 +78,13 @@ class RunnerTest < Test::Unit::TestCase
end
should "have an announcement message for notification" do
- message = @runner.message
+ message = @grader.message
assert_match "New metrics", message
assert_match "#{@config['url']}/#{@project.name}/output", message
end
should "use _site/:project for output_path" do
- assert_equal File.expand_path(File.join(@config['site'], @project.name)), @runner.output_path
+ assert_equal File.expand_path(File.join(@config['site'], @project.name)), @grader.output_path
end
end
@@ -94,42 +94,42 @@ class RunnerTest < Test::Unit::TestCase
end
should "have an announcement message for notification" do
- message = @runner.message
+ message = @grader.message
assert_match "New metrics", message
assert_match "#{@config['url']}/private/#{@project.name}/output", message
end
should "use _site/private/:project for output_path" do
- assert_equal File.expand_path(File.join(@config['site'], "private", @project.name)), @runner.output_path
+ assert_equal File.expand_path(File.join(@config['site'], "private", @project.name)), @grader.output_path
end
end
should "use _site/scores/:project for scores_path" do
- assert_equal File.expand_path(File.join(@config['site'], "scores", @project.name)), @runner.scores_path
+ assert_equal File.expand_path(File.join(@config['site'], "scores", @project.name)), @grader.scores_path
end
should "use _site/archive/:project for archive_path" do
- assert_equal File.expand_path(File.join(@config['site'], "archive", @project.name)), @runner.archive_path
+ assert_equal File.expand_path(File.join(@config['site'], "archive", @project.name)), @grader.archive_path
end
should "set build artifacts and prepare metric_fu for configure" do
- mock(ENV)['CC_BUILD_ARTIFACTS'] = @runner.output_path
+ mock(ENV)['CC_BUILD_ARTIFACTS'] = @grader.output_path
config = "config"
mock(config).reset
mock(config).template_class = AwesomeTemplate
mock(config).metrics = mock(config).graphs = [:flog, :flay, :rcov, :reek, :roodi]
mock(config).rcov = anything
- mock(config).data_directory = @runner.archive_path
+ mock(config).data_directory = @grader.archive_path
mock.proxy(MetricFu::Configuration).run.yields(config)
- @runner.configure
+ @grader.configure
assert_equal Hash.new, MetricFu.report.instance_variable_get(:@report_hash)
end
context "given already configured" do
setup do
- @runner.configure
+ @grader.configure
end
should "successfully generate output" do
@@ -153,16 +153,16 @@ class RunnerTest < Test::Unit::TestCase
stub(MetricFu).graph { graph }
mock(MetricFu).graphs.stub!.each.yields(one_graph)
- @runner.generate
- assert @runner.success?
+ @grader.generate
+ assert @grader.success?
end
end
should "be unsuccessful if some problem arises" do
stub(MetricFu).metrics { raise "some problem" }
mock(STDERR).puts(anything)
- @runner.generate
- assert ! @runner.success?
+ @grader.generate
+ assert ! @grader.success?
end
end
@@ -172,69 +172,69 @@ class RunnerTest < Test::Unit::TestCase
stub(YAML).load_file(File.join(MetricFu.base_directory, "report.yml")) { @report }
stub(File).exist?(anything) { false }
stub(FileUtils).mkdir_p(anything)
- stub(File).open(@runner.scores_path, "w")
+ stub(File).open(@grader.scores_path, "w")
end
should "load old scores if they exist" do
old_scores = "old scores"
- mock(File).exist?(@runner.scores_path) { true }
- mock(YAML).load_file(@runner.scores_path) { old_scores }
+ mock(File).exist?(@grader.scores_path) { true }
+ mock(YAML).load_file(@grader.scores_path) { old_scores }
- @runner.score
- assert_equal old_scores, @runner.old_scores
+ @grader.score
+ assert_equal old_scores, @grader.old_scores
end
should "set old score if it's not there" do
- mock(File).exist?(@runner.scores_path) { false }
- mock(FileUtils).mkdir_p(File.dirname(@runner.scores_path))
+ mock(File).exist?(@grader.scores_path) { false }
+ mock(FileUtils).mkdir_p(File.dirname(@grader.scores_path))
- @runner.score
- assert_equal Hash.new, @runner.old_scores
+ @grader.score
+ assert_equal Hash.new, @grader.old_scores
end
should "load and write scores from report yml" do
- mock(File).open(@runner.scores_path, "w")
+ mock(File).open(@grader.scores_path, "w")
- @runner.score
+ @grader.score
- assert_equal @report[:flay][:total_score].to_s, @runner.scores[:flay]
- assert_equal @report[:flog][:total].to_s, @runner.scores[:flog_total]
- assert_equal @report[:flog][:average].to_s, @runner.scores[:flog_average]
- assert_equal @report[:roodi][:problems].size.to_s, @runner.scores[:roodi]
- assert_equal @report[:rcov][:global_percent_run].to_s, @runner.scores[:rcov]
- assert_equal "9", @runner.scores[:reek]
+ assert_equal @report[:flay][:total_score].to_s, @grader.scores[:flay]
+ assert_equal @report[:flog][:total].to_s, @grader.scores[:flog_total]
+ assert_equal @report[:flog][:average].to_s, @grader.scores[:flog_average]
+ assert_equal @report[:roodi][:problems].size.to_s, @grader.scores[:roodi]
+ assert_equal @report[:rcov][:global_percent_run].to_s, @grader.scores[:rcov]
+ assert_equal "9", @grader.scores[:reek]
end
context "with scores" do
setup do
- stub(@runner).scores { "scores" }
- stub(@runner).message { "message" }
- stub(@runner).scoreboard { "scoreboard" }
+ stub(@grader).scores { "scores" }
+ stub(@grader).message { "message" }
+ stub(@grader).scoreboard { "scoreboard" }
end
context "with different old score" do
setup do
- stub(@runner).old_scores { "old scores" }
+ stub(@grader).old_scores { "old scores" }
end
should "return true for score_changed?" do
- assert @runner.score_changed?
+ assert @grader.score_changed?
end
end
context "with similar old score" do
setup do
- stub(@runner).old_scores { @runner.scores }
+ stub(@grader).old_scores { @grader.scores }
end
should "return false for score_changed?" do
- assert ! @runner.score_changed?
+ assert ! @grader.score_changed?
end
end
should "skip notification if config value is there" do
@config['skip_notification'] = true
- @runner.notify
+ @grader.notify
mock(Tinder::Campfire).new.never
end
@@ -243,7 +243,7 @@ class RunnerTest < Test::Unit::TestCase
mock(STDERR).puts(anything)
mock(Tinder::Campfire).new.never
- @runner.notify
+ @grader.notify
end
should "not skip notification if config value isn't there" do
@@ -254,16 +254,16 @@ class RunnerTest < Test::Unit::TestCase
mock(@project).notifiers.mock!.first.mock!.config { project_config }
room = "room"
- mock(room).speak(@runner.message)
- mock(room).paste(@runner.scoreboard)
+ mock(room).speak(@grader.message)
+ mock(room).paste(@grader.scoreboard)
mock(room).leave
campfire = "campfire"
mock(campfire).login(project_config["user"], project_config["pass"])
mock(campfire).find_room_by_name(project_config["room"]) { room }
mock(Tinder::Campfire).new(project_config["account"], :ssl => true) { campfire }
- @runner.notify
+ @grader.notify
end
end
end
View
@@ -1,31 +1,31 @@
require 'test_helper'
class ReportCardTest < Test::Unit::TestCase
- context "running report_card" do
+ context "grading report_card" do
setup do
@config = {'integrity_config' => '/path/to/integrity/config.yml'}
stub(ReportCard).config { @config }
@project = Integrity::Project.new
end
- should "run if project name is valid" do
+ should "grade if project name is valid" do
stub(@project).name { "awesome" }
mock(Integrity).new(@config['integrity_config'])
mock(Integrity::Project).all.mock!.each.yields(@project)
- mock(ReportCard::Runner).new(@project, @config).mock!.run
- ReportCard.run
+ mock(ReportCard::Grader).new(@project, @config).mock!.grade
+ ReportCard.grade
end
- should "not run if project name is ignored" do
+ should "not grade if project name is ignored" do
@config['ignore'] = "1\.9"
stub(@project).name { "awesome 1.9" }
mock(Integrity).new(@config['integrity_config'])
mock(Integrity::Project).all.mock!.each.yields(@project)
- mock(ReportCard::Runner).new(@project, @config).never
- ReportCard.run
+ mock(ReportCard::Grader).new(@project, @config).never
+ ReportCard.grade
end
end

0 comments on commit 3cbb766

Please sign in to comment.