Browse files

Start the move to test/unit, context, matchy and rr.

And let's get the specs cleaned up, once and for all!
  • Loading branch information...
1 parent 72b9434 commit ae0b188c3bbd060fd1f1a5702a41ecd649e69470 @foca foca committed Dec 13, 2008
Showing with 101 additions and 1 deletion.
  1. +30 −1 Rakefile
  2. +51 −0 test/test_fixtures.rb
  3. +20 −0 test/test_helper.rb
View
31 Rakefile
@@ -1,8 +1,37 @@
require File.dirname(__FILE__) + "/lib/integrity"
+require "rake/testtask"
+require "rcov/rcovtask"
require 'spec/rake/spectask'
require 'spec/rake/verify_rcov'
-task :default => ["spec:coverage", "spec:coverage:verify"]
+desc "Run all tests and check test coverage"
+task :default => "test:coverage:verify"
+
+Rake::TestTask.new
+
+namespace :test do
+ desc "Measure test coverage"
+ Rcov::RcovTask.new(:coverage) do |rcov|
+ rcov.pattern = "test/**/*_test.rb"
+ rcov.rcov_opts = %w(--html)
+ end
+
+ namespace :coverage do
+ desc "Verify coverage is at 100%"
+ task :verify => "test:coverage" do
+ File.read("coverage/index.html") =~ /<tt class='coverage_total'>\s*(\d+\.\d+)%\s*<\/tt>/
+ coverage = $1.to_f
+
+ puts
+ if coverage == 100
+ puts "\e\[1;32m100% coverage! Awesome!\e\[0;0m"
+ else
+ puts "\e\[1;31mOnly #{coverage}% You can do better ;)\e\[0;0m"
+ exit 1
+ end
+ end
+ end
+end
Spec::Rake::SpecTask.new(:spec) do |t|
t.spec_opts = ["--color", "--format", "progress"]
View
51 test/test_fixtures.rb
@@ -0,0 +1,51 @@
+require 'rubygems'
+require 'dm-sweatshop'
+
+include DataMapper::Sweatshop::Unique
+
+class Array
+ def pick
+ self[rand(self.length)]
+ end
+end
+
+def commit_metadata
+ meta_data = <<-EOS
+---
+:author: #{/\w+ \w+ <\w+@example.org>/.gen}
+:message: >-
+ #{/\w+/.gen}
+:date: #{Time.now}
+EOS
+end
+
+def notifier_config
+ {}.tap do |config|
+ 5.times { config[/\w+/.gen] = /\w+/.gen }
+ end
+end
+
+Integrity::Project.fixture do
+ { :name => (name = unique { /\w+/.gen }),
+ :uri => "git://github.com/#{/\w+/.gen}/integrity.git",
+ :branch => %w[master bug_4567 build-in-badground].pick,
+ :command => "rake master",
+ :public => true,
+ :building => false }
+end
+
+Integrity::Build.fixture do
+ { :output => /[:paragraph:]/.gen,
+ :successful => true,
+ :commit_identifier => Digest::SHA1.hexdigest(/[:paragraph:]/.gen),
+ :commit_metadata => commit_metadata }
+end
+
+Integrity::Notifier.fixture(:irc) do
+ class Integrity::Notifier::IRC < Integrity::Notifier::Base
+ def self.to_haml; ""; end
+ def deliver!; nil; end
+ end
+
+ { :name => "IRC", :config => notifier_config }
+end
View
20 test/test_helper.rb
@@ -0,0 +1,20 @@
+require File.dirname(__FILE__) + '/../lib/integrity'
+require File.dirname(__FILE__) + '/test_fixtures'
+
+require "ruby-debug"
+require "test/unit"
+require "redgreen"
+require "context"
+require "matchy"
+require "rr"
+
+class Test::Unit::TestCase
+ include RR::Adapters::TestUnit
+end
+
+# Gives a nicer syntax than declaring TestCase subclasses in tests
+def describe(name, &block)
+ Class.new(Test::Unit::TestCase) do
+ context(name.to_s, &block)
+ end
+end

0 comments on commit ae0b188

Please sign in to comment.