Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add spec for Table.

  • Loading branch information...
commit 9075602504bd2efb7366325400bf3a36efa1870f 1 parent 27904ab
@gabebw authored
Showing with 59 additions and 5 deletions.
  1. +6 −5 lib/gitsucker/table.rb
  2. +53 −0 spec/gitsucker/table_spec.rb
View
11 lib/gitsucker/table.rb
@@ -1,7 +1,8 @@
module Gitsucker
class Table
- def initialize(repo_name)
+ def initialize(repo_name, output = STDOUT)
@repo_name = repo_name
+ @output = output
end
def output_results
@@ -22,7 +23,7 @@ def column_spacing
def display_author_stats
Repo.new(@repo_name).forking_authors.each do |author|
- printf column_spacing,
+ @output.printf column_spacing,
author.name,
author.public_repo_count,
author.original_repo_count,
@@ -30,13 +31,13 @@ def display_author_stats
author.ruby_repo_count,
author.js_repo_count,
author.score
- puts
+ @output.puts
end
end
def display_header
- puts column_spacing % Author::STAT_TYPES
- puts '='*80
+ @output.puts column_spacing % Author::STAT_TYPES
+ @output.puts '='*80
end
end
end
View
53 spec/gitsucker/table_spec.rb
@@ -0,0 +1,53 @@
+require 'spec_helper'
+
+require 'stringio'
+describe Gitsucker::Table, '#output_results' do
+ it 'displays a header' do
+ io = StringIO.new
+ Gitsucker::Table.new('my-repo', io).output_results
+ expected_regexp = Regexp.new(Gitsucker::Author::STAT_TYPES.join('\s+'))
+ io.string.split("\n").first.should =~ expected_regexp
+ end
+
+ it 'displays a line below the header' do
+ io = StringIO.new
+ Gitsucker::Table.new('my-repo', io).output_results
+ line = '='*80
+ io.string.split("\n")[1].should == line
+ end
+
+ it 'displays author stats' do
+ authors = [stub('author one',
+ :name => 'one',
+ :public_repo_count => 6,
+ :original_repo_count => 5,
+ :forked_repo_count => 4,
+ :ruby_repo_count => 3,
+ :js_repo_count => 2,
+ :score => 1),
+ stub('author two',
+ :name => 'two',
+ :public_repo_count => 1,
+ :original_repo_count => 2,
+ :forked_repo_count => 3,
+ :ruby_repo_count => 4,
+ :js_repo_count => 5,
+ :score => 6)]
+ repo = stub('repo', :forking_authors => authors)
+ Gitsucker::Repo.stubs(:new => repo)
+ io = StringIO.new
+ Gitsucker::Table.new('my-repo', io).output_results
+
+ authors.each do |author|
+ expected_regexp = Regexp.new([
+ author.name,
+ author.public_repo_count,
+ author.original_repo_count,
+ author.forked_repo_count,
+ author.ruby_repo_count,
+ author.js_repo_count,
+ author.score].join('\s+'))
+ io.string.should =~ expected_regexp
+ end
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.