Permalink
Browse files

working on tests

  • Loading branch information...
bkayser committed Nov 13, 2011
1 parent a406ebd commit e69625b34b45bad4410c0ebad0e740c947c5a57f
Showing with 58 additions and 10 deletions.
  1. +0 −1 Gemfile
  2. +1 −3 Gemfile.lock
  3. +5 −2 Rakefile
  4. +13 −2 lib/netloc.rb
  5. +39 −2 test/test_netloc.rb
View
@@ -10,5 +10,4 @@ group :development do
gem "shoulda", ">= 0"
gem "bundler", "~> 1.0.0"
gem "jeweler", "~> 1.6.4"
- gem "rcov", ">= 0"
end
View
@@ -7,8 +7,7 @@ GEM
git (>= 1.2.5)
rake
rake (0.9.2.2)
- rcov (0.9.9)
- shoulda (2.10.3)
+ shoulda (2.11.3)
PLATFORMS
ruby
@@ -17,5 +16,4 @@ DEPENDENCIES
bundler (~> 1.0.0)
jeweler (~> 1.6.4)
rake (>= 0.9.2)
- rcov
shoulda
View
@@ -1,7 +1,9 @@
# encoding: utf-8
+# Bill Kayser
-require 'rubygems'
+ require 'rubygems'
require 'bundler'
+
begin
Bundler.setup(:default, :development)
rescue Bundler::BundlerError => e
@@ -12,6 +14,7 @@ end
require 'rake'
require 'jeweler'
+
Jeweler::Tasks.new do |gem|
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
gem.name = "netloc"
@@ -37,4 +40,4 @@ Rake::TestTask.new(:test) do |test|
end
task :default => :test
-
+
View
@@ -17,6 +17,7 @@ def run
command = "git log #{@from}..#{@to}"
command << " --numstat"
command << " --oneline"
+ command << " --ignore-all-space"
command << " '--pretty=format:<%h> <%an> %s'"
command << " '--author=#{@author}'" if @author
@output = `#{command}`.split("\n").map(&:chomp)
@@ -37,16 +38,26 @@ def parse
@io.puts "#$1 #$3 (#$2)" if @verbose
end
end
+ @io.puts "no activity found." if @files.empty?
end
def report
for label, value in [["app code", @apps],['test code', @tests],['other', @others]] do
- @io.puts "#{'%14s'%label}: #{net(value)} lines in #{value.size} files" unless value.empty?
+ next if value.empty?
+ net = net(value)
+ @io.puts "#{label}:"
+ @io.puts " #{'%7i' % value.size} files modified"
+ @io.puts " #{'%7i' % size_of_changes(value)} lines changed"
+ @io.puts " #{'%+7i' % net} net lines #{ net >= 0 ? 'added' : 'removed'}"
end
end
def net(values)
- '%+7i' % values.flatten.reduce{|a,b| a + b }
+ values.flatten.reduce{|a,b| a + b }
+ end
+
+ def size_of_changes(values)
+ values.flatten.reduce{|a,b| (a > 0 ? a : 0) + (b > 0 ? b : 0) }
end
def process_line added, removed, file
View
@@ -1,7 +1,44 @@
require 'helper'
class TestNetloc < Test::Unit::TestCase
- should "probably rename this file and start testing for real" do
- flunk "hey buddy, you should probably rename this file and start testing for real"
+
+ def setup
+ @io = StringIO.new
+ end
+ should "compile stats in latest commit" do
+ n = Netloc.new :out => @io, :verbose => true
+ n.run
+ end
+
+ should "compile stats over historical commit" do
+ n = Netloc.new :out => @io, :verbose => false, :since => '11f3f', :until => '5e3d2'
+ n.run
+ assert_equal <<EOF.strip, @io.string.strip
+app code:
+ 2 files modified
+ 37 lines changed
+ +12 net lines added
+test code:
+ 1 files modified
+ 14 lines changed
+ +12 net lines added
+other:
+ 5 files modified
+ 74 lines changed
+ +74 net lines added
+EOF
+ end
+
+ should "omit commits by other user" do
+ n = Netloc.new :out => @io, :verbose => false, :since => '11f3f', :until => '5e3d2', :author => 'Joe'
+ n.run
+ assert @io.string =~ /no activity found/
+ end
+
+ should "include commits by me" do
+ n = Netloc.new :out => @io, :verbose => false, :since => '11f3f', :until => '5e3d2', :author => 'Bill Kayser'
+ n.run
+ assert @io.string !~ /no activity found/
end
+
end

0 comments on commit e69625b

Please sign in to comment.